Search code examples
pythongoogle-mapsgoogle-places-api

Google Places API: how to search by type and location in Python


I'm following the example I found on the main page of GitHub relative to googlemaps and I'm writing my own code in order to retrieve all cinemas from a specific area.

The code is this:

import googlemaps

gmaps = googlemaps.Client(key='MyGoogleKey')

search_loction = gmaps.location('40.714224, -73.961452').type('movie_theater')
print (search_loction)

It returns me the error:

Traceback (most recent call last):
  File "GoogleMap.py", line 5, in <module>
    search_loction = gmaps.location('40.714224, -73.961452')
AttributeError: 'Client' object has no attribute 'location'

If I follow the guide, yes, the attribute [location] is allowed enter image description here

So what am I doing wrong?


Solution

  • According to the documentation, you should use

    gmaps.places(...) with the location as a parameter.

    Something like

    gmaps.places(location=(lat,lng), type="movie_theater")