import requests
import json
def getplace(lat, lon):
url = "http://maps.googleapis.com/maps/api/geocode/json?"
url += "latlng=%s,%s&sensor=false" % (lat, lon)
data = {'key': 'your-api-key-goes-here'} # If using your free 5 calls, include no data and just doa get request on the url
v = requests.post(url=url, data=data)
j = json.loads(v.text)
components = j['results'][0]['address_components']
country = town = None
for c in components:
if "country" in c['types']:
country = c['long_name']
if "locality" in c['types']:
town = c['long_name']
return town, country
print(getplace(45.425533, -75.69248))
print(getplace(45.525533, -77.69248))
你说的是反向地理编码。最简单的方法是使用googlemaps地理编码API。你知道吗
你不需要注册就可以做到这一点,但是你每天只能打4-5个电话。你可以免费注册一个相对较高的电话号码(20-25k上次我检查),如果你超过了,你必须支付。你知道吗
上述输出: (‘渥太华’,‘加拿大’) (“巴里湾”,“加拿大”)
您可以打印原始响应
print(v.text
,以查看数据对象并找到您真正关心的字段相关问题 更多 >
编程相关推荐