【问题标题】:Google Maps Geocoding API is not returning coordinates from the complete list of addressesGoogle Maps Geocoding API 未返回完整地址列表中的坐标
【发布时间】:2018-06-27 10:54:12
【问题描述】:

它在单个地址或几个地址上工作正常,但我试图从包含 200 个地址的 CSV 中读取地址,但程序只返回几个坐标。当我在不处理异常的情况下运行它时,它也会给出超出范围的错误索引。

import requests
import json
import csv

apiKey = ""

with open('address.csv') as csvDataFile:
  try:
      csvReader = csv.reader(csvDataFile)
      for row in csvReader:
        # print(row)
          r = requests.get("https://maps.googleapis.com/maps/api/geocode/json?address=" + str(row) + "&key=" + apiKey)
          d = json.loads(r.content)
          print(d['results'][0]['geometry']['location'])
  except:
          `enter code here`pass

【问题讨论】:

    标签: python python-3.x google-maps google-maps-api-3 geocoding


    【解决方案1】:

    在循环中添加等待。软速率限制为每秒 50 个调用。

    https://developers.google.com/maps/documentation/geocoding/usage-limits

    【讨论】:

    • 在打印后添加了 time.sleep(3) 但仍然出现相同的错误。
    • 打印d会看到什么?
    • print(d) 包含一个结果字典,其中包括地址组件、几何等。但我只为几何(长/纬度)切片。
    • 我的意思是当你捕捉到异常时。尝试打印rd
    猜你喜欢
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-18
    • 2013-02-23
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多