python - 使用 Python 检索街道地址的美国邮政编码

标签 python gis

使用 Python 检索街道地址的美国邮政编码的最有效方法是什么?这甚至是可能的吗?

最好是包含本地数据库的东西,而不是某种远程 API 调用。

在此先感谢您提供的任何帮助。

最佳答案

可能是一个开始: The Zip Code Database Project

googlemaps – Google Maps and Local Search APIs in Python

GoogleMaps.geocode(query, sensor='false', oe='utf8', ll='', spn='', gl='')

Given a string address query, return a dictionary of information about that location, including its latitude and longitude. Interesting bits:

>>> 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

关于python - 使用 Python 检索街道地址的美国邮政编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3663556/

相关文章:

python - 将字符串作为项目添加到 QT/Python 中的 qtableWidget

db2 - 空间 SQL : Most suitable datatype for a square?

gis - NetLogo - 将值应用于多边形内的面片

sql-server - 线串之间的相似性

python - 从另一个模型获取值列表

python - Flask 装饰器怎么会有参数?

r - 使用光栅化函数光栅化小多边形的问题

java - 地理工具,Java : How to convert shapefile data from DOR to usable polygons with Latitude and Longitude coordinates

python - 如何从 Python 在 Odoo-8 中执行查询?

python - 为 python reduce 的明显限制让路