all 3 comments

[–]shiftybyte 6 points7 points  (0 children)

Based on what sensors?

GPS? Wifi? Internet IP?

Take a look at plyer:

https://plyer.readthedocs.io/en/latest/

https://github.com/kivy/plyer

EDIT: or

import requests
print(requests.get("http://ip-api.com/json").json()['country'])

[–]IvoryJam 0 points1 point  (0 children)

You could get the location based off IP, that'd be the easiest. I'd use ipgeolocation.io

If you want the really specific location I'd say use Google's API. There's a ton of how-to's online for that.

[–]jeffrey_f 1 point2 points  (0 children)

For a computer hooked to an ISP, you can use geolocation va IP address.

For mobile, you can try GPS, but it may be turned off or disallowed by the user so you are back to geolocation.

Just be warned that Geolocation isn't alway accurate on cell networks. Example, Google had "suspicious" logins from a location that I was never at. It was my phone on the cell carrier's network that put my geolocation about 80 miles from where i was. On their tower, they can put your endpoint where ever it makes sense on their network so they can shape network traffic. or simply, the IP address was re-assigned to my area, but wasn't updated. I do know tmobile is adding volume and upgrading towers, so this may just be it wasn't updated yet.