这个问题可能看起来很复杂,但现有的问题并没有解决我的需要.
我在Stackoverflow和Google中检查了很多关于这个主题的问题,但我找不到有效的方法.几乎在所有线程中人们都建议这个网站http://www.hostip.info/来检测用户位置.当我试图查看该网站时,它说我"没有关于你的位置的线索".在其他一些网站上,我的城市是根据我的IP地址确定的,这是错误的.
但是在google.com或bing.com上,网站确切地确定了我的位置.他们是怎么做到的?我怎样才能确切地获得游客的位置(这个城市就足够了)?在某些网站上,我看到Google Chrome向我提出一个问题,"允许此网站分享您的位置".他们如何使用此功能?
答案是"通过机器/地理位置的IP地址"
有一个用php编写的插件很容易做到这样的任务,
步骤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";
?>
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请查看插件网站:点击此处.
注意:如果您想按照自己的方式做同样的事情,则需要IP地址位置的数据.然后你就可以找到它.