+ 5
Is there any way to get precise location of user in python?
I've tried geocode and the location using IP address. It doesn't work the way I want it to, which is, like a webpage on a browser does. It asks if you want to allow it to access your location and then gets your precise location. Any help would be much appreciated. Thanks
13 Antworten
+ 14
Ok, from what i understood, the physical locations they give you on websites like
https://mylocation.org/
come from their use of maintained databases linking ip adresses with real locations. It's more accurate than only ip adresses, but not exact.
Here you'll find such a database, free to use:
https://dev.maxmind.com/geoip/geoip2/geolite2/
+ 13
I don't get it, where did you see that browsers can get precise location ?
Do you have an example ?
+ 13
OK, I've seen many situations when Google gets mistaken locations. I think that's how I told you: they are using a database, and they refine it by using all kind of data. Google is best at this.
But you won't be able to access this database I think. At least for free. The one on the free site will work, but less accurate.
What could be this info you're speaking about that we accept to be used, unless it's IP ?
+ 13
My pleasure, and please show me if you get something working well 😊
+ 12
That's also what this stackoverflow thread says. They are using wifi id, and they build a database.
So unother way to get it could be by scraping the result of a query on g. maps ...
+ 10
terminal:
pip install geocoder
then:
import geocoder
g = geocoder.ip('me')
print(g.latlng)
print(g.city)
https://geocoder.readthedocs.io/index.html
+ 6
Yes this doesn't work. It depends on the access point.
+ 5
Cépagrave
Thanks but the website you posted says itself that : *IP geolocation is inherently imprecise. *
I need to fetch user's precise location so I can't use the IP address thingy, it would never be precise up to a certain point.
Moreover, if you connect to someone's personal hotspot it gives you varying degrees of inaccurate location data.
I was wondering if there's a technique to get precise location info like browsers do. Thank you
+ 5
Ok this could be it. I'm gonna try this. Much thanks Cépagrave 😀🤗
+ 5
Sure thing!
+ 4
Try opening Google maps on your web browser for instance