4

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.

askedJan 23, 2019 at 6:05
Bukaida's user avatar
1
  • 2
    Don'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?CommentedJan 23, 2019 at 14:22

2 Answers2

5

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 location

Result

R-1, GA Block, Sector III, Salt Lake City, Kolkata, West Bengal 700106, India
answeredJan 30, 2019 at 12:22
Vadim Gremyachev's user avatar
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, works perfectly in command line. Anyway to show the same on Map? I have unrestricted Test API.
with the latest geopy library ( 2.2.0 ) thegeolocator.reverse() call defaults theexactly_one=True argument. Thus the code should be modified tolocation = geolocator.reverse("22.5757344, 88.4048656") if location: location.address
5

You 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:

https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/utils/geocoder/#q%3D22.575734%252C88.404866

For further details have a look at the documentation in github.

I hope this helps!

answeredJan 30, 2019 at 18:50
xomena's user avatar

1 Comment

It is showing a screen full of information as my API key is unrestricted. I have seen the Github before asking help here, but it was a overkill for a noob like me.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.