我需要将地址地理编码为纬度、经度对以显示在 Google map 上,但我需要在 Django 中在服务器端执行此操作。我只能找到对 Javascript V3 API 的引用。我如何从 Python 中做到这一点?
最佳答案
我强烈建议使用 geopy .它会返回经纬度,之后你可以在谷歌JS客户端中使用它。
>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim()
>>> location = geolocator.geocode("175 5th Avenue NYC")
>>> print(location.address)
Flatiron Building, 175, 5th Avenue, Flatiron, New York, NYC, New York, ...
>>> print((location.latitude, location.longitude))
(40.7410861, -73.9896297241625)
此外,您可以通过使用 GoogleV3
类作为地理定位器来明确定义您想要使用的 Google 服务
>>> from geopy.geocoders import GoogleV3
>>> geolocator = GoogleV3()
关于python - 如何从Python获取地址坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5807195/