【发布时间】:2018-02-08 21:09:20
【问题描述】:
我正在通过 Python 库使用 Google 的地理编码 API(已试用 GeoPy 1.11.0)。 对于诸如“Utica”之类的查询,我得到一个响应:
{u'geometry': {u'location_type': u'APPROXIMATE', u'bounds': {u'northeast':
{u'lat': 43.132269, u'lng': -75.1609059}, u'southwest': {u'lat':
43.0644689, u'lng': -75.295296}}, u'viewport': {u'northeast': {u'lat':
43.132269, u'lng': -75.1609059}, u'southwest': {u'lat': 43.0644689, u'lng':
-75.295296}}, u'location': {u'lat': 43.100903, u'lng': -75.232664}},
u'address_components': [{u'long_name': u'Utica', u'types': [u'locality',
u'political'], u'short_name': u'Utica'}, {u'long_name': u'Oneida County',
u'types': [u'administrative_area_level_2', u'political'], u'short_name':
u'Oneida County'}, {u'long_name': u'New York', u'types':
[u'administrative_area_level_1', u'political'], u'short_name': u'NY'},
{u'long_name': u'United States', u'types': [u'country', u'political'],
u'short_name': u'US'}], u'place_id': u'ChIJKXZqNVE32YkRhvztGCY2GhE',
u'formatted_address': u'Utica, NY, USA', u'types': [u'locality',
u'political']}
问题在于美国有多个 Utica,例如 Utica, NY 和 Utica, WI。我希望 Google 会返回所有可能以 Utica 为名的地方,有没有办法做到这一点?
以下是使用 Google 的 GeoPy 的代码:
locations = ["Utica"]
from geopy.geocoders import GoogleV3
geolocator = GoogleV3(api_key=GoogleAPIKey)
for location in locations:
print location
results = geolocator.geocode(query=location, language='en', exactly_one=False, timeout=5)
for result in results:
print result.raw
【问题讨论】:
标签: python google-maps geocoding google-geocoding-api geopy