Google Maps Geocoding API不会从完整的地址列表中返回坐标

时间:2018-01-18 11:20:24

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

它在单个地址或几个地址上工作正常,但我试图从包含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

1 个答案:

答案 0 :(得分:0)

在循环中添加等待。软速率限制为每秒50次呼叫。

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