简体   繁体   中英

find location using device IP address

I am using ionic2.

I found my device IP address using Cordova plugin add cordova-plugin-networkinterface .

Here is my IP address

192.168.1.104

How can I find a location using device IPAddress?

Kindly advice me,

Thanks

you can get the location using the ExternalIp and I would use the freegeoip.net , so calling this URL you can able to get the JSON Object as follows:

Output:

{
  "ip": "116.12.250.1",
  "country_code": "SG",
  "country_name": "Singapore",
  "region_code": "01",
  "region_name": "Central Singapore Community Development Council",
  "city": "Singapore",
  "zip_code": "",
  "time_zone": "Asia/Singapore",
  "latitude": 1.2931,
  "longitude": 103.8558,
  "metro_code": 0
}

Limitations:

10,000 requests per hour

For the Location (As per your Original Question)

you can use Geobytes

usage:

$.getJSON('http://gd.geobytes.com/GetCityDetails?callback=?', function(data) {
  console.log(JSON.stringify(data, null, 2));
});

Returns:

{
  "geobytesforwarderfor": "",
  "geobytesremoteip": "116.12.250.1",
  "geobytesipaddress": "116.12.250.1",
  "geobytescertainty": "99",
  "geobytesinternet": "SA",
  "geobytescountry": "Saudi Arabia",
  "geobytesregionlocationcode": "SASH",
  "geobytesregion": "Ash Sharqiyah",
  "geobytescode": "SH",
  "geobyteslocationcode": "SASHJUBA",
  "geobytescity": "Jubail",
  "geobytescityid": "13793",
  "geobytesfqcn": "Jubail, SH, Saudi Arabia",
  "geobyteslatitude": "27.004999",
  "geobyteslongitude": "49.660999",
  "geobytescapital": "Riyadh ",
  "geobytestimezone": "+03:00",
  "geobytesnationalitysingular": "Saudi Arabian ",
  "geobytespopulation": "22757092",
  "geobytesnationalityplural": "Saudis",
  "geobytesmapreference": "Middle East ",
  "geobytescurrency": "Saudi Riyal",
  "geobytescurrencycode": "SAR",
  "geobytestitle": "Saudi Arabia"
}

Limitations

  • 16,384 requests per hour
  • Can return the wrong location
  • No SSL(https) with free plan

Only an external IP address has a chance at locating you in the real world. To get it from JavaScript you would need a friendly website that provides an easy to use API to it's services.

A quick search on turned up places like http://ip-api.com/ that provides both the public IP address and your location. 可以找到http://ip-api.com/等提供公共IP地址和您的位置的地方。 Beware that the "resolution" of the IP address may be quite crude. APIs you pay for may be able to do better.

To manually get your home's public IP address you can log into your router using the instructions on the router's label. Somewhere within is a menu that shows your public IP address, though they may call it something like a WAN address. If you password is something stupid like "password", now is the time to change it. I like to write it on a small piece of tape and put it mostly out of site on the router, not covering any hole.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM