简体   繁体   English

使用设备IP地址查找位置

[英]find location using device IP address

I am using ionic2. 我正在使用ionic2。

I found my device IP address using Cordova plugin add cordova-plugin-networkinterface . 我使用Cordova plugin add cordova-plugin-networkinterface找到了设备IP地址。

Here is my IP address 这是我的IP地址

192.168.1.104 192.168.1.104

How can I find a location using device IPAddress? 如何使用设备IP地址找到位置?

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: 您可以使用ExternalIp来获取位置,而我将使用freegeoip.net ,因此调用此URL即可获取JSON对象,如下所示:

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 每小时10,000个请求

For the Location (As per your Original Question) 对于位置(根据您的原始问题)

you can use Geobytes 你可以使用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 每小时16,384个请求
  • Can return the wrong location 可以返回错误的位置
  • No SSL(https) with free plan 没有免费计划的SSL(https)

Only an external IP address has a chance at locating you in the real world. 只有外部IP地址才有机会在现实世界中找到您。 To get it from JavaScript you would need a friendly website that provides an easy to use API to it's services. 要从JavaScript获取它,您将需要一个友好的网站,该网站为其服务提供易于使用的API。

A quick search on geolocation ip API turned up places like http://ip-api.com/ that provides both the public IP address and your location. 快速搜索地理位置ip API可以找到http://ip-api.com/等提供公共IP地址和您的位置的地方。 Beware that the "resolution" of the IP address may be quite crude. 请注意,IP地址的“解析”可能非常粗糙。 APIs you pay for may be able to do better. 您付费的API可能会做得更好。

To manually get your home's public IP address you can log into your router using the instructions on the router's label. 要手动获取家中的公共IP地址,您可以使用路由器标签上的说明登录路由器。 Somewhere within is a menu that shows your public IP address, though they may call it something like a WAN address. 菜单中的某个位置显示了您的公共IP地址,尽管他们可能将其称为WAN地址。 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. 我喜欢将其写在一小块胶带上,然后将其放置在路由器上的大部分位置,而不覆盖任何孔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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