我正在使用ionic2。使用设备IP地址查找位置
我使用Cordova plugin add cordova-plugin-networkinterface
找到了我的设备IP地址。
这里是我的IP地址
192.168.1.104
如何可以找到使用设备ip地址的位置?
请咨询我,
感谢
我正在使用ionic2。使用设备IP地址查找位置
我使用Cordova plugin add cordova-plugin-networkinterface
找到了我的设备IP地址。
这里是我的IP地址
192.168.1.104
如何可以找到使用设备ip地址的位置?
请咨询我,
感谢
只有一个外部IP地址,具有定位你在现实世界中的机会。要从JavaScript获得它,您需要一个友好的网站,为其服务提供易用的API。
快速搜索地理定位IP API找到了像http://ip-api.com/这样的地方,它提供了公共IP地址和您的位置。请注意,IP地址的“解析”可能相当粗糙。您付费的API可能会做得更好。
要手动获取您家的公共IP地址,您可以使用路由器标签上的说明登录到您的路由器。其中的某个地方是一个显示公共IP地址的菜单,尽管它们可能称之为WAN地址。如果你的密码像“密码”一样愚蠢,现在是时候改变它。我喜欢把它写在一小块磁带上,并把它放在路由器上的大部分地方,而不是覆盖任何洞。
可以使用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"
}
个限制
返回错误的位置
感谢您的答复。我可以如何获得外部IP。 –
在这种情况下,只能从您的/ a服务器。 – Stephan