Reputation: 23
I am currently working on a project requiring to identify where a device's country address is. I have tried using Montemagno's Geolocator but the problem is if the user does not use location services or gps on his device. I am thinking that it might be possible using IP address but I don't know how or any recommendation might help. Thanks.
Upvotes: 2
Views: 880
Reputation: 1457
Do you have enough space in the device and bandwidth?
If you have more than 5MB free space and can download update, then you can download the offine gelocation database and query it locally. You can visit IP2Location LITE for free database. However, please take note that you need to update it periodically.
If you do not have enough space, you can use remote API call to get the information. One such free service is IPInfoDB and you can find sample codes in the page. It is a free service since 2010.
Upvotes: 0
Reputation: 26
You need to create a http GET request to get the results on JSON format you may use IP API to get country information by ip address. Example get request on :
return a json data which have country information.
{ "query": "24.48.0.1", "status": "success", "country": "Canada", "countryCode": "CA", "region": "QC", "regionName": "Quebec", "city": "Montreal", "zip": "H1S", "lat": 45.5808, "lon": -73.5825, "timezone": "America/Toronto", "isp": "Le Groupe Videotron Ltee", "org": "Videotron Ltee", "as": "AS5769 Videotron Telecom Ltee" }
Upvotes: 1
Reputation: 1614
You should use a service like MaxMind's GeoIP2 and periodically download databases with updates. If you stay contacting a remote API each time, it will be slow. It's better to have a local database that you refresh on a schedule.
There's a free version, too.
Upvotes: 0
Reputation: 21
"You can use IpInfo to get a user's country by their internet address. unless they're under VPN or Proxy this is your best bet." From user Stavm on This question
Upvotes: 0