我想通过
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