Search code examples
google-mapsgoogle-geocodergoogle-geocoding-api

how to know whether a point is on land or water using google maps api


I want to know whether a point is on land or water using google maps geocoding api.

If I give my coordinate point as (40,-74) which is on water body, I am still getting address which is shown below.

the address is:1416 Highland Ave, Cinnaminson, NJ 08077, USA results[0].geometry.locationType:ROOFTOP results[0].types[0].toString():street_address(which has to be "natural_feature")

I am using java client library to do this. Anyone help me because I have strucked up here and has to submit my assignment where soon. Thanks in Advance.


Solution

  • You can filter results of reverse geocoding by result type and location type. In result type you can look for natural_feature and location type should be GEOMETRIC_CENTER or APPROXIMATE to exclude any ROOFTOP address that can be close to given point on the land.

    Please have a look at the following request:

    https://maps.googleapis.com/maps/api/geocode/json?latlng=40%2C-74&result_type=natural_feature&location_type=GEOMETRIC_CENTER%7CAPPROXIMATE&key=YOUR_API_KEY

    The first two items in response are:

    • North Atlantic Ocean (type: natural_feature, place ID: ChIJeQ3JDsMo3QoRBGVpwFckZUQ)
    • Atlantic Ocean (type: natural_feature, place ID: ChIJ_7hu48qBWgYRT1MQ81ciNKY)

    Now if I execute the same request for the point on the land:

    https://maps.googleapis.com/maps/api/geocode/json?latlng=40.044043%2C-74.124069&result_type=natural_feature&location_type=GEOMETRIC_CENTER%7CAPPROXIMATE&key=YOUR_API_KEY

    The first result will be 'Drum Point Rd, Brick, NJ 08723, USA' of type route.

    Hope it helps.