繁体   English   中英

使用设备IP地址查找位置

[英]find location using device IP address

我正在使用ionic2。

我使用Cordova plugin add cordova-plugin-networkinterface找到了设备IP地址。

这是我的IP地址

192.168.1.104

如何使用设备IP地址找到位置?

请告诉我,

谢谢

您可以使用ExternalIp来获取位置,而我将使用freegeoip.net ,因此调用此URL即可获取JSON对象,如下所示:

输出:

{
  "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
}

限制:

每小时10,000个请求

对于位置(根据您的原始问题)

你可以使用Geobytes

用法:

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

返回:

{
  "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"
}

限制

  • 每小时16,384个请求
  • 可以返回错误的位置
  • 没有免费计划的SSL(https)

只有外部IP地址才有机会在现实世界中找到您。 要从JavaScript获取它,您将需要一个友好的网站,该网站为其服务提供易于使用的API。

快速搜索地理位置ip API可以找到http://ip-api.com/等提供公共IP地址和您的位置的地方。 请注意,IP地址的“解析”可能非常粗糙。 您付费的API可能会做得更好。

要手动获取家中的公共IP地址,您可以使用路由器标签上的说明登录路由器。 菜单中的某个位置显示了您的公共IP地址,尽管他们可能将其称为WAN地址。 如果您的密码很愚蠢,例如“密码”,那么现在是时候更改它了。 我喜欢将其写在一小块胶带上,然后将其放置在路由器上的大部分位置,而不覆盖任何孔。

暂无
暂无

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

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