Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get an address from coordinates using google maps?

I'm just curious. Maybe for a future project. I want to know if it's possible to retrieve an address from a giving coordinate via the Google API.

like image 703
Aaron de Windt Avatar asked Apr 04 '12 10:04

Aaron de Windt


People also ask

How do I pull an address from Google Maps?

What's the address? is a simple tool that can help you find the approximate address of any point on Google Maps. All you have to do is drag the red marker pin to another location and the approximate snail address of that place should pop-up in a marker window.

How do I find a physical address from GPS coordinates?

On the Google Maps app, you can't pull up a context menu. To find the address for your coordinates, hold your finger down over the red pin that shows your coordinates. Then, after 1-3 seconds, the address will pop up on the bottom of your screen.

Can Google Maps show addresses?

On your computer, open Google Maps and make sure you're signed in. Search for a contact's name or address. Matching contacts will appear in the suggestions. To see your contact on the map, choose a name or address.


3 Answers

yes. Just use Google Geocoding and Places API https://developers.google.com/maps/documentation/geocoding/ and https://developers.google.com/maps/documentation/places/

Example (derived from here):

var geocoder;

function initialize() {
  geocoder = new google.maps.Geocoder();
}

function codeLatLng(lat, lng) {
  var latlng = new google.maps.LatLng(lat, lng);
  geocoder.geocode({
    'latLng': latlng
  }, function (results, status) {
    if (status === google.maps.GeocoderStatus.OK) {
      if (results[1]) {
        console.log(results[1]);
      } else {
        alert('No results found');
      }
    } else {
      alert('Geocoder failed due to: ' + status);
    }
  });
}

google.maps.event.addDomListener(window, 'load', initialize);
like image 166
rijndael Avatar answered Nov 02 '22 05:11

rijndael


It's possible to access this information sending a simple GET request to the geocode endpoint.

e.g. hitting https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=API_KEY would produce the following response:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "277",
               "short_name" : "277",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Bedford Avenue",
               "short_name" : "Bedford Ave",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Williamsburg",
               "short_name" : "Williamsburg",
               "types" : [ "neighborhood", "political" ]
            },
            {
               "long_name" : "Brooklyn",
               "short_name" : "Brooklyn",
               "types" : [ "sublocality", "political" ]
            },
            {
               "long_name" : "Kings",
               "short_name" : "Kings",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "New York",
               "short_name" : "NY",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "11211",
               "short_name" : "11211",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "277 Bedford Avenue, Brooklyn, NY 11211, USA",
         "geometry" : {
            "location" : {
               "lat" : 40.714232,
               "lng" : -73.9612889
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 40.7155809802915,
                  "lng" : -73.9599399197085
               },
               "southwest" : {
                  "lat" : 40.7128830197085,
                  "lng" : -73.96263788029151
               }
            }
         },
         "place_id" : "ChIJd8BlQ2BZwokRAFUEcm_qrcA",
         "types" : [ "street_address" ]
      },

  ... Additional results[] ...

https://developers.google.com/maps/documentation/geocoding/intro#reverse-example

like image 20
Bower Avatar answered Nov 02 '22 04:11

Bower


TomTom Maps APIs provides with a Reverse Geocoding end point which gives a structured JSON.

You can try it with the API Explorer.

For example :

curl -X GET "https://api.tomtom.com/search/2/reverseGeocode/37.8328,-122.27669.json?key=*****" -H "accept: */*"

Will get you

{
  "summary": {
    "queryTime": 6,
    "numResults": 1
  },
  "addresses": [
    {
      "address": {
        "buildingNumber": "1001",
        "streetNumber": "1001",
        "routeNumbers": [],
        "street": "42nd Street",
        "streetName": "42nd Street",
        "streetNameAndNumber": "1001 42nd Street",
        "countryCode": "US",
        "countrySubdivision": "CA",
        "countrySecondarySubdivision": "Alameda",
        "countryTertiarySubdivision": "Oakland",
        "municipality": "Oakland, Emeryville",
        "postalCode": "94608",
        "municipalitySubdivision": "Oakland, Emeryville",
        "country": "United States",
        "countryCodeISO3": "USA",
        "freeformAddress": "1001 42nd Street, Emeryville, CA 94608",
        "boundingBox": {
          "northEast": "37.832893,-122.276230",
          "southWest": "37.832777,-122.277006",
          "entity": "position"
        },
        "countrySubdivisionName": "California",
        "localName": "Emeryville"
      },
      "position": "37.832844,-122.276688"
    }
  ]
}

You can get a free API KEY (no credit card needed) and try our tutorials!

Disclosure: I am employed at TomTom.

like image 26
JJ Rojas Avatar answered Nov 02 '22 03:11

JJ Rojas