I am getting the geo-data in a json file (geo.json) which has the following structure
{"userId":"Geo-data","data":{"mocked":false,"timestamp":1548173963281,"coords":{"speed":0,"heading":0,"accuracy":20.20400047302246,"longitude":88.4048656,"altitude":0,"latitude":22.5757344}}}All I want is to print the place details corresponding to above data and if possible to show it on MAP also.I have tried the following code with geopy
from geopy.geocoders import Nominatimgeolocator = Nominatim()location = geolocator.reverse("22.5757344, 88.4048656")print(location.address)print((location.latitude, location.longitude))But the location I am getting is not very accurate. Whereas the same coordinates give good results inhttps://www.latlong.net/Show-Latitude-Longitude.htmlI also have a Google API key. However, what ever references I found so far are almost like a project themselves and a overkill for a beginner like me. The geopy code was fine but the location accuracy is very poor. Please help.
P.SI have tried geocoder also as
import geocoderg = 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)However it is printing 'None' in all the cases.
- 2Don't know why someone has marked it negative. It is not a duplicate and I have tried to explain everything I tried so that someone can help. How else am I suppose to ask?Bukaida– Bukaida2019-01-23 14:22:22 +00:00CommentedJan 23, 2019 at 14:22
2 Answers2
You could consider to switch fromOpenStreetMap Nominatim provider toGoogle Geocoding. Then, the following example seems returns the address you expect it to:
from geopy.geocoders import GoogleV3geolocator = GoogleV3(api_key=google_key)locations = geolocator.reverse("22.5757344, 88.4048656")if locations: print(locations[0].address) # select first locationResult
R-1, GA Block, Sector III, Salt Lake City, Kolkata, West Bengal 700106, India2 Comments
geolocator.reverse() call defaults theexactly_one=True argument. Thus the code should be modified tolocation = geolocator.reverse("22.5757344, 88.4048656") if location: location.addressYou can try a Python Client for Google Maps Services library that can be found at
https://github.com/googlemaps/google-maps-services-python
This is a wrapper library for Google Maps API web service requests developed by Googlers. The code snapshot is the following
import googlemapsgmaps = googlemaps.Client(key='Add Your Key here')# Look up an address with reverse geocodingreverse_geocode_result = gmaps.reverse_geocode((22.5757344, 88.4048656))This code returns addressR-1, GA Block, Sector III, Salt Lake City, Kolkata, West Bengal 700106, India similar to the result that you can see in Geocoder tool:
For further details have a look at the documentation in github.
I hope this helps!
1 Comment
Explore related questions
See similar questions with these tags.

