Python中的地理编码

问题描述 投票:1回答:2

我在Python中使用地理编码器包来获取一组地址的坐标(大约30k)。我收到以下错误:

状态代码来自https://maps.googleapis.com/maps/api/geocode/json的未知:错误 - HTTPSConnectionPool(host ='maps.googleapis.com',port = 443):使用url超出最大重试次数:/ maps / api / geocode / json?address = Rancho + Palos + Verdes%2CCA% 2CUS&bounds =&components =&region =&language =(由ProxyError引起('无法连接到代理。',超时('超时',)))

如果我添加time.sleep(x)函数,我收到错误的次数会减少,但会显着增加执行代码所需的时间。有没有更有效的方法来运行代码?

以下是代码片段:

for add in clean_address:
    g=geocoder.google(add)
    time.sleep(7)
    if(g.ok==True):
        lat.append(str(g.lat))
        lon.append(str(g.lng))
    if(g.ok==False):
        lat.append("")
        lon.append("")
python python-3.x geocoding
2个回答
2
投票

Google API有一个use limitation。但是,您甚至可以使用收集大量地理编码服务的地理编码器库。我建议您使用对使用没有任何限制的ArcGis api并且非常准确。用法很简单:

g=geocoder.arcgis(add)
lat.append(g.x)
lon.append(g.y)

1
投票

您的地址为30K,限制为每天2.5K。

谷歌引用相关的docs

要使用Google Maps Geocoding API,您必须在Google API控制台上注册您的应用项目,并获取可以添加到您的应用或网站的Google API密钥。

在这之后,these是限制:

标准API的用户:

  • 每天2,500个免费请求,以客户端和服务器端查询的总和计算。
  • 每秒50个请求,计算为客户端和服务器端查询的总和。
© www.soinside.com 2019 - 2024. All rights reserved.