我想通過
IP地址獲取我當前的(區域,區號或郵政編碼,州,國家)的位置。如何獲得我當前所在地區,地區,城市,國家
我在下面的代碼中獲取IP地址。
$myip = $_SERVER['REMOTE_ADDR'];
output :- 122.161.20.5
我的代碼: -
<?php
$ip_addr = '122.161.20.5';
$geoplugin = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip_addr));
if (is_numeric($geoplugin['geoplugin_latitude']) && is_numeric($geoplugin['geoplugin_longitude'])) {
$lat = $geoplugin['geoplugin_latitude'];
$long = $geoplugin['geoplugin_longitude'];
}
echo '<pre>';
print_r($geoplugin);
echo '<pre>';
?>
以上的IP地址提供位置新德里但這不是我的當前位置。
請幫幫我。
這可能是這個特定服務可以做到的最好的。嘗試一種不同的方式,或爲用戶提供一種更正其自動檢測位置的方法。 – halfer