我使用下面的代码来获取地址的纬度和经度:
from googlemaps import GoogleMaps
gmaps = GoogleMaps(api_key)
address = 'Constitution Ave NW & 10th St NW, Washington, DC'
lat, lng = gmaps.address_to_latlng(address)
print lat, lng
但出现以下错误
File "C:/Users/Pavan/PycharmProjects/MGCW/latlong6.py", line 1, in <module>
from googlemaps import GoogleMaps
ImportError: cannot import name GoogleMaps
我见过另一个与此类似的问题,但该解决方案对我不起作用。
Use geopy https://pypi.python.org/pypi/geopy相反,不需要 api-key。
从他们的例子来看:
from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.geocode("175 5th Avenue NYC")
print(location.address)
print((location.latitude, location.longitude))
prints:
Flatiron Building, 175, 5th Avenue, Flatiron, New York, NYC, New York, 10010, United States of America
(40.7410861, -73.9896297241625)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)