これは、私はこれがあるsd
はTypeError:文字列のインデックスは、私はこのエラーを回避するためにintegers.What行う必要がありますする必要があります
に'lat'
と'lng'
にint型を取得したい私の辞書sd = gmaps.geocode('New Delhi')
[{'address_components': [{'long_name': 'New Delhi', 'short_name': 'New Delhi', 'types': ['locality', 'political']}, {'long_name': 'Delhi', 'short_name': 'DL', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'India', 'short_name': 'IN', 'types': ['country', 'political']}], 'formatted_address': 'New Delhi, Delhi, India', 'geometry': {'bounds': {'northeast': {'lat': 28.65048, 'lng': 77.3449601}, 'southwest': {'lat': 28.4041, 'lng': 77.07301009999999}}, 'location': {'lat': 28.6139391, 'lng': 77.2090212}, 'location_type': 'APPROXIMATE', 'viewport': {'northeast': {'lat': 28.65048, 'lng': 77.3449601}, 'southwest': {'lat': 28.4041, 'lng': 77.07301009999999}}}, 'place_id': 'ChIJLbZ-NFv9DDkRzk0gTkm3wlI', 'types': ['locality', 'political']}]
です私はそれを実行すると、コードの私のラインは
lat = []
lng = []
for x in sd:
for y in sd:
for z in y["geometry"]:
lat.append(z["location"]["lat"])
for x in sd:
for y in sd:
for z in y["geometry"]:
lng.append(z["location"]["lng"])
print(lat, lng)
このエラーは
表示されますTypeError: string indices must be integers
私はあなたが私を助けることを願っています。
助けてくれてありがとう –