GoogleプレイスリバースジオコードAPIを使用して、指定された住所の緯度と経度を返します。 APIは、多数のネストされたオブジェクトを含む大量のJSONファイルを返します。ここにGoogleのdocumentationがあります。Python/DjangoネストされたJSONを参照する
私はgeometry.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オブジェクトを参照するかどうかはわかりません。
アクセスしようとしているデータを表示する必要があります。エラーが示すように、そのデータ構造の少なくとも1つのレベルは、dictではなくリストです。 –