如何有效地检测用户城市



这个问题可能看起来是重复的,但现有的问题并没有解决我的需求。

我已经在Stackoverflow和Google中检查了很多关于这个主题的问题,但我找不到有效的方法。几乎所有线程中,人们都建议此站点 http://www.hostip.info/以检测用户位置。当我试图检查那个网站时,它说我"不知道你的位置"。在其他一些网站,我的城市是根据我的IP地址确定的,这是错误的。

但在 google.com 或 bing.com,这些网站准确地确定了我的位置。他们是怎么做到的?我怎样才能准确地获得访客位置(只是城市就足够了(?在某些网站上,我看到谷歌浏览器向我抛出了一个问题,"允许这个网站分享你的位置"。他们如何使用此功能?

答案是"通过机器的IP地址/地理位置">

有一个用php编写的插件可以非常轻松地完成此类任务,

步骤-1(从这里下载插件。

步骤-2(小代码片段

<?php
    require_once('geoplugin.class.php');
    $geoplugin = new geoPlugin();
    $geoplugin->locate();
    echo "Geolocation results for {$geoplugin->ip}: <br />n".
        "City: {$geoplugin->city} <br />n".
        "Region: {$geoplugin->region} <br />n".
        "Area Code: {$geoplugin->areaCode} <br />n".
        "DMA Code: {$geoplugin->dmaCode} <br />n".
        "Country Name: {$geoplugin->countryName} <br />n".
        "Country Code: {$geoplugin->countryCode} <br />n".
        "Longitude: {$geoplugin->longitude} <br />n".
        "Latitude: {$geoplugin->latitude} <br />n".
    "Currency Code: {$geoplugin->currencyCode} <br />n".
    "Currency Symbol: {$geoplugin->currencySymbol} <br />n".
    "Exchange Rate: {$geoplugin->currencyConverter} <br />n";
?>

有关更多详细信息,请查看插件网站:单击此处。

注意:如果你想用你的方式做同样的事情,你需要一个IP数据 地址位置。然后之后你可以找到它。

简单易用的代码来检测城市 o 国家 我希望对您有所帮助

    $geoplugin = unserialize( file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $_SERVER['REMOTE_ADDR']) );
   echo ("<h1>".$geoplugin['geoplugin_countryCode']."</h1> <br>");
   echo ("<h1>".$geoplugin['geoplugin_countryName']."</h1> <br>");
   echo ("<h1>".$geoplugin['geoplugin_regionCode']."</h1> <br>");
   echo ("<h1>".$geoplugin['geoplugin_regionName']."</h1><br>");
   echo ("<h1>".$geoplugin['geoplugin_currencyCode']."</h1><br>");
   echo ("<h1>".$geoplugin['geoplugin_currencySymbol']."</h1><br>");
   echo ("<h1>".$geoplugin['geoplugin_currencySymbol_UTF8']."</h1><br>");
   echo ("<h1>".$geoplugin['geoplugin_currencyConverter']."</h1>");

优质的服务:

1( http://ipinfo.io/123.123.123.123

2( http://ip-api.com/php/123.123.123.123

3(检测国家和城市(PHP,GeoIP Maxmind(

最新更新