我在一个json文件(geo.json)中获取地理数据,该文件具有以下结构
{"userId":"Geo-data","data":{"mocked":false,"timestamp":1548173963281,"coords":{"speed":0,"heading":0,"accuracy":20.20400047302246,"longitude":88.4048656,"altitude":0,"latitude":22.5757344}}}我只想打印与上述数据相对应的地点细节,如果可能的话,也可以在地图上显示出来。
from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.reverse("22.5757344, 88.4048656")
print(location.address)
print((location.latitude, location.longitude))但是我得到的位置不是很精确。在https://www.latlong.net/Show-Latitude-Longitude.html中,相同的坐标给出了很好的结果,但是我也有一个Google键。然而,到目前为止,我所发现的参考资料几乎就像一个项目本身,对于像我这样的初学者来说,这是一个过分的选择。位势码很好,但定位精度很低。请帮帮忙。
P.S .我也尝试过地理编码器
import geocoder
g = geocoder.google([45.15, -75.14], method='reverse')
print(g.city)
print(g.state)
print(g.state_long)
print(g.country)
print(g.country_long)然而,它在所有情况下都打印“无”。
发布于 2019-01-30 12:22:50
您可以考虑从OpenStreetMap Nominatim提供程序切换到Google地理编码。然后,下面的示例似乎返回您期望的地址:
from geopy.geocoders import GoogleV3
geolocator = GoogleV3(api_key=google_key)
locations = geolocator.reverse("22.5757344, 88.4048656")
if locations:
print(locations[0].address) # select first location结果
R-1, GA Block, Sector III, Salt Lake City, Kolkata, West Bengal 700106, India发布于 2019-01-30 18:50:33
您可以尝试一个用于Google服务库的Python客户端,可以在
https://github.com/googlemaps/google-maps-services-python
这是由Google开发的Googlers web服务请求的包装库。代码快照如下
import googlemaps
gmaps = googlemaps.Client(key='Add Your Key here')
# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((22.5757344, 88.4048656))此代码返回address R-1, GA Block, Sector III, Salt Lake City, Kolkata, West Bengal 700106, India,类似于您可以在Geo编码器工具中看到的结果:
有关更多细节,请参阅github中的文档。
我希望这能帮到你!
https://stackoverflow.com/questions/54320931
复制相似问题