Skip to content

Instantly share code, notes, and snippets.

@Aqua-4
Created March 9, 2020 09:04
Show Gist options
  • Save Aqua-4/0c026d0c9a67310953c5ba9878da2c94 to your computer and use it in GitHub Desktop.
Save Aqua-4/0c026d0c9a67310953c5ba9878da2c94 to your computer and use it in GitHub Desktop.
gmaps-api v3 - get country name and area_lv_1 name
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 9 12:47:29 2020
@author: parashar
"""
import googlemaps
api_key="***api_key_here***"
gmaps = googlemaps.Client(key=api_key)
def get_loc(place_str):
place_str=place_str.replace('Photos and Videos of ','')
print(place_str)
loca = gmaps.find_place(input=place_str, input_type="textquery",fields=['place_id','plus_code','formatted_address'])
info = gmaps.place(loca.get('candidates',[{}])[0].get('place_id'))
area_1=None;country = None
for item in info['result']['address_components']:
if( 'administrative_area_level_1' in item.get('types')):
area_1 = item.get('long_name')
elif( 'country' in item.get('types')):
country = item.get('long_name')
print(area_1,country)
p_code = loca.get('candidates',[{}])[0].get('plus_code')
print(p_code)
return info
info = get_loc('Novotel Hyderabad Convention Centre')
info = get_loc('Malpani resorts, Sangamner')
info = get_loc('Naples, Italy')
info = get_loc('Vomero, Campania, Italy')
info = get_loc('Photos and Videos of Puerto Escondido, Oaxaca')
info = get_loc('Windmill Lake')
info = get_loc('Australia')
info = get_loc('Sydney Australia')
info = get_loc('The Abbey Food & Bar - West Hollywood')
info = get_loc('Pimpri Chinchwad Science Park')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment