1

I'm trying to reverse geocode location by placeId using https://github.com/googlemaps/google-maps-services-python, but I get an empty array as a result.

gmaps = googlemaps.Client(key='<my-api-key>')
place_id = "ChIJnQrgk4u6EmsRVqYSfnjhaOk"
location = gmaps.geolocate({'placeId':place_id})

Location gets returned as [].

How can I do that, since the documentation for the library is not the best.

intelis
  • 7,829
  • 14
  • 58
  • 102
  • Well, another way of doing this is first, get the coordinates of the PlaceID that you are getting then use the reverse geocoding for this corrdinats. There is a sample code here in the [Google Maps JavaScript documentation](https://developers.google.com/maps/documentation/javascript/examples/geocoding-place-id) that you can get the coordinates by using the Place ID. For more information, check this related [question](http://stackoverflow.com/questions/29659688). – KENdi Mar 31 '17 at 14:52

1 Answers1

2

You are trying to use gmaps.geolocate, but that is for use of the geolocation API, not the geocoding API. You need to use the reverse geocoder documented here:

https://googlemaps.github.io/google-maps-services-python/docs/2.4.6/

I was able to get this to work with the following code:

import googlemaps

gmaps = googlemaps.Client(key='MY_API_KEY')
place_id = "ChIJnQrgk4u6EmsRVqYSfnjhaOk"
# Geocoding an address
geocode_result = gmaps.reverse_geocode(place_id)


print geocode_result

I hope this helps!