Google Place Search (Python)
October 11, 2019Package
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
.
Place Search
import googlemaps
GOOGLE_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:
- algo-trading
- algolia
- analytics
- android
- android-ktx
- android-permission
- android-studio
- apps-script
- bash
- binance
- bootstrap
- bootstrapvue
- chartjs
- chrome
- cloud-functions
- coding-interview
- contentresolver
- coroutines
- crashlytics
- crypto
- css
- dagger2
- datastore
- datetime
- docker
- eslint
- firebase
- firebase-auth
- firebase-hosting
- firestore
- firestore-security-rules
- flask
- fontawesome
- fresco
- git
- github
- glide
- godot
- google-app-engine
- google-cloud-storage
- google-colab
- google-drive
- google-maps
- google-places
- google-play
- google-sheets
- gradle
- html
- hugo
- inkscape
- java
- java-time
- javascript
- jetpack-compose
- jetson-nano
- kotlin
- kotlin-serialization
- layout
- lets-encrypt
- lifecycle
- linux
- logging
- lubuntu
- markdown
- mate
- material-design
- matplotlib
- md5
- mongodb
- moshi
- mplfinance
- mysql
- navigation
- nginx
- nodejs
- npm
- nuxtjs
- nvm
- pandas
- payment
- pip
- pwa
- pyenv
- python
- recylerview
- regex
- room
- rxjava
- scoped-storage
- selenium
- social-media
- ssh
- ssl
- static-site-generator
- static-website-hosting
- sublime-text
- ubuntu
- unit-test
- uwsgi
- viewmodel
- viewpager2
- virtualbox
- vue-chartjs
- vue-cli
- vue-router
- vuejs
- vuelidate
- vuepress
- web-development
- web-hosting
- webpack
- windows
- workmanager
- wsl
- yarn