在Python中使用googleapi获取坐标(经度和纬度)

2024-09-27 21:30:59 发布

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

如果我有如下地址数据帧:

id                Address                        Latitude       Longitude 
01   Via Benedetto Croce 112, Rome, Italy          
02   Via Aristide Leonori 46, Rome, Italy
03   Viale Marconi 197, Rome, Italy

如何使用Python中的googleapi获得它们的坐标(经度和纬度)?谢谢。在

^{pr2}$

下面是我从Python客户机库中找到的googlemapsapi Web服务,但是它失败了:raise超时.googlemaps()

https://github.com/googlemaps/google-maps-services-python

import googlemaps
from datetime import datetime

gmaps = googlemaps.Client(key='googlemap ak')
# Geocoding an address
geocode_result = gmaps.geocode('Via Benedetto Croce 112, Rome, Italy')
print(geocode_result)

Tags: 数据importiddatetimeaddress地址resultvia
1条回答
网友
1楼 · 发布于 2024-09-27 21:30:59

试试这个。它使用提名。在

import pandas as pd
from geopy.geocoders import Nominatim
geolocator = Nominatim()
data = [
        {'Id':'01', 'Address': "Via Benedetto Croce 112, Rome, Italy", 'Latitude': None, 'Longitude' :None},
        {'Id':'02', 'Address': "Via Aristide Leonori 46, Rome, Italy", 'Latitude': None, 'Longitude' :None},
        {'Id':'03', 'Address': "Viale Marconi 197, Rome, Italy", 'Latitude': None, 'Longitude' :None}
       ]
df = pd.DataFrame(data)
df['city_coord']  = df['Address'].apply(geolocator.geocode)
df['Latitude'] = df['city_coord'].apply(lambda x: (x.latitude))
df['Longitude'] = df['city_coord'].apply(lambda x: (x.longitude))
print(df[['Address',  'Id',   'Latitude','Longitude']])

enter image description here

相关问题 更多 >

    热门问题