How to access current location of any user using python [closed]
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/loc37.3845,-122.0881
See https://ipinfo.io/developers for more details.
Since http://freegeoip.net/json
API endpoint is deprecated and will stop working on July 1st, 2018. So, they release new API http://api.ipstack.com
.
So, you may try out this with new API:
import requestsimport jsonsend_url = "http://api.ipstack.com/check?access_key=YOUR_ACCESS_KEY"geo_req = requests.get(send_url)geo_json = json.loads(geo_req.text)latitude = geo_json['latitude']longitude = geo_json['longitude']city = geo_json['city']
In order to get your own ACCESS_KEY
, you have to first create an account on ipstack.com
which is free at https://ipstack.com/signup/free.
Along with latitude
, longitude
and city
; you can also fetch zip
, continent_code
, continent_name
, country_code
, country_name
, region_code
, region_name
.
Limitation: Free account only allow you 10,000 requests/month. If you requirement is more then you can upgrade you account.
For more information about this new API you can visit at https://github.com/apilayer/freegeoip
Reference: @JishnuM answer