我正在使用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