【发布时间】:2020-03-06 13:34:32
【问题描述】:
我一直在尝试对包含经纬度数据的 csv 进行反向地理编码,以找到与坐标对应的邮政编码。我有一个来自 google 的 API,并尝试使用 pygeocoder,但是它无法识别 API(参见下面的代码)。
import pandas as pd
from pygeocoder import Geocoder
import numpy as np
lndn = pd.read_csv(r'my file pathway', sep=',')
results = Geocoder.reverse_geocode(lndn['lat'][0], lndn['lng'][0])
每次我收到并出错:
GeocoderError: Error REQUEST_DENIED
Query: https://maps.google.com/maps/api/geocode/json?region=&latlng=51.495290%2C-0.166223&sensor=false&bounds=&language=
然后我使用了 googlemaps 包:
import googlemaps
import pandas as pd
gmaps = googlemaps.Client(key='my API')
lndn = pd.read_csv(r'my file pathway', sep=',')
results = gmaps.reverse_geocode((lndn['lat'][0], lndn['lng'][0]))
results
这有效,但只是打印了所有信息,即
[{u'address_components': [{u'long_name': u'35',
u'short_name': u'35',
u'types': [u'street_number']},
{u'long_name': u'Walton Street',
u'short_name': u'Walton St',
u'types': [u'route']},
{u'long_name': u'Chelsea',
u'short_name': u'Chelsea',
u'types': [u'neighborhood', u'political']},
{u'long_name': u'London',
u'short_name': u'London',
u'types': [u'postal_town']},
{u'long_name': u'Greater London',
u'short_name': u'Greater London',
u'types': [u'administrative_area_level_2', u'political']},
{u'long_name': u'England', etc............
我可以看到邮政编码在那里。有没有办法从这一切中提取和打印邮政编码?
【问题讨论】:
标签: python google-maps reverse-geocoding geocoder