Google Place Search (Python)

Package

Check for latest version: https://pypi.org/project/googlemaps/

pip install -U googlemaps

API Key

Create API Key at Google Cloud Console -> Credentials

  • Create credentials -> API Key (Copy API Key)
  • Restrict API Key:
    • Application restrictions: for cli and backend server, API could be restricted by IP Address. But since I am planning to use Cloud Functions, thus I have to use None.
    • API restrictions: I select Restrict Key and select Places API.
import googlemapsGOOGLE_API_KEY = ...gmaps = googlemaps.Client(key=GOOGLE_API_KEY)result = gmaps.find_place(    input='bahn mi',    input_type='textquery',    # https://developers.google.com/places/web-service/search#Fields    fields=['place_id', 'name', 'types', 'geometry', 'formatted_address'],    # circle:radius@lat,lng    # rectangle:south,west|north,east    location_bias='point:3.0189534,101.6311891',    # https://developers.google.com/maps/faq#languagesupport    language='en'    )

Sample result

{  "candidates": [    {      "formatted_address": "5, Jalan Kenari 8, Bandar Puchong Jaya, 47100 Puchong, Selangor, Malaysia",      "geometry": {        "location": {          "lat": 3.0478144,          "lng": 101.6230629        },        "viewport": {          "northeast": {            "lat": 3.049169229892722,            "lng": 101.6244009298927          },          "southwest": {            "lat": 3.046469570107277,            "lng": 101.6217012701073          }        }      },      "name": "Banh Mi Cafe Bandar Puchong Jaya",      "place_id": "ChIJVYN_lVtLzDERmjMdXcXG39E",      "types": [        "restaurant",        "food",        "point_of_interest",        "establishment"      ]    }  ],  "status": "OK"}
{  "candidates": [],  "status": "ZERO_RESULTS"}

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.