php – 如何有效地检测用户城市?
这个问题可能看起来很复杂,但现有的问题并没有解决我的需要.
我在Stackoverflow和Google中检查了很多关于这个主题的问题,但我找不到有效的方法.几乎在所有线程中人们都建议这个站点http://www.hostip.info/来检测用户位置.当我试图查看该网站时,它说我“没有关于你的位置的线索”.在其他一些网站上,我的城市是根据我的IP地址确定的,这是错误的. 但是在google.com或bing.com上,网站确切地确定了我的位置.他们是怎么做到的?我怎样才能确切地获得游客的位置(这个城市就足够了)?在某些网站上,我看到Google Chrome向我提出一个问题,“允许此网站分享您的位置”.他们如何使用此功能? 解决方法
有一个用php编写的插件很容易做到这样的任务, 步骤1)从here.下载插件 步骤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"; ?> 有关详细信息,请查看插件网站:click here.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |