Search code examples
google-mapsgoogle-geocoding-apigeocode

Google Geocoding API - Get lat lon of street in front of house instead of Rooftop


When geocoding this address (1369 47th St, Brooklyn, NY 11219) thru the geocode API or the directions API I do not get the Lat Lon of the street in front of the house.

It gives the Lat and Lon of the house. How can we get the street in front?


Solution

  • In order to get coordinate of the street in front of the building you can execute a second request to get the nearest road from the Roads API.

    So, the first request https://maps.googleapis.com/maps/api/geocode/json?address=1369%2047th%20St%2C%20Brooklyn%2C%20NY%2011219&key=YOUR_API_KEY

    returns coordinate of building 40.6352581,-73.9890749.

    Now, let's execute the nearest road request from Roads API

    https://roads.googleapis.com/v1/nearestRoads?points=40.6352581%2C-73.9890749&key=YOUR_API_KEY

    It will return the coordinate of the nearest road segment

    {
      "snappedPoints":[
        {
          "location":{
        "latitude":40.635110805821085,
        "longitude":-73.98922999212694
          },
          "originalIndex":0,
          "placeId":"ChIJDUk6jixFwokRVMe62BkvZ0A"
        }
      ]
    }
    

    as shown in my screenshot

    enter image description here

    I hope this helps!