从Google API提取格式化的地址

时间:2018-10-17 07:29:07

标签: python google-maps google-maps-api-3

我想仅通过Google Maps API从公司名称中提取格式化的地址。我该怎么做?

import googlemaps
from datetime import datetime


gmaps = googlemaps.Client(key='My_API_Key')


result = gmaps.geocode('Global Orange, street, NL')

print(result)

[{'address_components': [{'long_name': 'Haarlemmerstraat', 'short_name': 
'Haarlemmerstraat', 'types': ['route']}, {'long_name': 'Amsterdam', 
'short_name': 'Amsterdam', 'types': ['locality', 'political']}, 
{'long_name': 'Netherlands', 'short_name': 'NL', 'types': ['country', 
'political']}, {'long_name': '1013 EX', 'short_name': '1013 EX', 'types': 
['postal_code']}], 'formatted_address': '124E, Haarlemmerstraat, 1013 EX 
Amsterdam, Netherlands', 'geometry': {'location': {'lat': 52.381314, 'lng': 
4.8905885}, 'location_type': 'GEOMETRIC_CENTER', 'viewport': {'northeast': 
{'lat': 52.3826629802915, 'lng': 4.891937480291502}, 'southwest': {'lat': 
52.3799650197085, 'lng': 4.889239519708497}}}, 'partial_match': True, 
'place_id': 'ChIJM80Szc4JxkcRAmkcZPAl58w', 'plus_code': {'compound_code': 
'9VJR+G6 Amsterdam, Netherlands', 'global_code': '9F469VJR+G6'}, 'types': 
['establishment', 'point_of_interest']}]

1 个答案:

答案 0 :(得分:0)

您在回复(结果)中输入了格式化的地址,不确定我是否关注。

""[{'address_components': [{'long_name': 'Haarlemmerstraat', 'short_name': 
'Haarlemmerstraat', 'types': ['route']}, {'long_name': 'Amsterdam', 
'short_name': 'Amsterdam', 'types': ['locality', 'political']}, 
{'long_name': 'Netherlands', 'short_name': 'NL', 'types': ['country', 
'political']}, {'long_name': '1013 EX', 'short_name': '1013 EX', 'types': 
['postal_code']}], ***'formatted_address': '124E, Haarlemmerstraat, 1013 EX 
Amsterdam, Netherlands',*** 'geometry': {'location': {'lat': 52.381314, 'lng': 
4.8905885}, 'location_type': 'GEOMETRIC_CENTER', 'viewport': {'northeast': 
{'lat': 52.3826629802915, 'lng': 4.891937480291502}, 'southwest': {'lat': 
52.3799650197085, 'lng': 4.889239519708497}}}, 'partial_match': True, 
'place_id': 'ChIJM80Szc4JxkcRAmkcZPAl58w', 'plus_code': {'compound_code': 
'9VJR+G6 Amsterdam, Netherlands', 'global_code': '9F469VJR+G6'}, 'types': 
['establishment', 'point_of_interest']}]