我使用googleplaces反向地理编码API返回给定地址的纬度和长度。API返回一个包含大量嵌套对象的大量JSON文件。这是谷歌的documentation。你知道吗
我想抓住几何.location.lat对象(请参阅文档)。下面是我当前的代码,后跟返回的错误:
address_coords = gmaps.geocode(raw_address)
# gmaps makes the API request and returns the JSON into address_coords
address_lat = address_coords['results']['geometry']['location']['lat']
address_lon = address_coords['results']['geometry']['location']['lng']
TypeError: List indices must be integers or slices, not str
我不知道如何引用那个JSON对象。你知道吗
这个错误告诉您,您试图将数组作为属性来索引。你知道吗
最有可能的
results
是数组,因此需要执行以下操作以获取索引0
处第一项的值:另一种可能性是
geometry
包含多个坐标,您可以类似地索引这些坐标:不管是哪种方式,您都应该漂亮地打印结构,以查看哪些属性是数组还是字典。你知道吗
相关问题 更多 >
编程相关推荐