Is there anyway that I can get the location of my device through python. Currently I am having to use selenium and open up a browser, use a location service website and setting the result of that to variables for lat/long.
But is there an easier way to do this?
UPDATE: I am using a 3G dongle on my RaspberryPi, so looking for a way to get the specific lat/long of it - I can successfully do this through web service, just wondering if there is a quicker way built into python for these requests?
In order to get the last location of the user, make use of the Java public class FusedLocationProviderClient. It is actually a location service that combines GPS location and network location to achieve a balance between battery consumption and accuracy.
Just send HTTP GET request to https://api.ipgeolocationapi.com with different parameters and get the JSON result. For example, the following HTTP GET request will give you a location of the specified IP address. The following request returns the country information specified by the ISO country code.
or, as simple as this
import geocoder g = geocoder.ip('me') print(g.latlng)
Others have mentioned a few services, but another one to consider is my own, https://ipinfo.io, which'll give you latitude, longitude and a bunch of other information:
Usage for Bash:
$ curl ipinfo.io { "ip": "24.6.61.239", "hostname": "c-24-6-61-239.hsd1.ca.comcast.net", "city": "Mountain View", "region": "California", "country": "US", "loc": "37.3845,-122.0881", "org": "AS7922 Comcast Cable Communications, LLC", "postal": "94040" }
If you only want the coordinate data you can get just that by requesting /loc
:
$ curl ipinfo.io/loc 37.3845,-122.0881
See https://ipinfo.io/developers for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With