如何使用Python以最有效的方式检索街道地址的美国邮政编码?这是可能的吗?
最好使用本地数据库而不是某种远程API调用。
提前感谢任何能够提供帮助的人。
googlemaps - Python中的Google Maps和本地搜索API
GoogleMaps.geocode(query, sensor='false', oe='utf8', ll='', spn='', gl='')
>>> gmaps = GoogleMaps(api_key)
>>> address = '350 Fifth Avenue New York, NY'
>>> result = gmaps.geocode(address)
>>> placemark = result['Placemark'][0]
>>> lng, lat = placemark['Point']['coordinates'][0:2]
# Note these are backwards from usual
>>> print lat, lng
40.6721118 -73.9838823
>>> details = placemark['AddressDetails']['Country']['AdministrativeArea']
>>> street = details['Locality']['Thoroughfare']['ThoroughfareName']
>>> city = details['Locality']['LocalityName']
>>> state = details['AdministrativeAreaName']
>>> zipcode = details['Locality']['PostalCode']['PostalCodeNumber']
>>> print ', '.join((street, city, state, zipcode))
350 5th Ave, Brooklyn, NY, 11215
https://github.com/smartystreets/LiveAddressSamples/blob/master/python/street-address.py
从示例中可以看出,该服务提供了完整的9位数字邮政编码,以及所有其他地址组件以及有关地址的一些元数据。