import googlemaps
key = 'YOUR_API_KEY'
address = '1600 Amphitheatre Parkway' # Google's address
gmaps = googlemaps.Client(key=key)
# Convert the given address to coordinates. You can use gmaps.reverse_geocode((lat, lng))
# to convert the coordinates back to an address
geocode_result = gmaps.geocode(address)
lat = geocode_result[0]['geometry']['location']['lat'] # Get the latitude
lng = geocode_result[0]['geometry']['location']['lng'] # Get the longitude
print(address, 'is at', (lat, lng))
上述网站使用googlemapsapi将地址转换为坐标(称为地理编码)。要使用Google Maps API,您需要一个API密钥
您可以按照here的说明获取API密钥。你知道吗
完成后,需要安装
googlemaps
Python包才能使用API:pip install googlemaps
以下代码将地址转换为坐标,并打印出给定地址所在的坐标:
相关问题 更多 >
编程相关推荐