从googleapi提取格式化地址

2024-04-25 23:34:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我只想通过googlemapsapi从公司名称中提取格式化的地址。我该怎么做?你知道吗

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']}]

Tags: nameimportdatetimecodelongextypesshort
1条回答
网友
1楼 · 发布于 2024-04-25 23:34:48

您在响应(结果)中有格式化的地址,不确定我是否在跟踪。你知道吗

""[{'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']}]

相关问题 更多 >

    热门问题