【发布时间】:2014-10-06 06:35:03
【问题描述】:
我正在本地主机上进行一些编码,并通过我的手机和平板电脑进行测试。
我计划使用$_SERVER['REMOTE_ADDR'] 获取用户 ip 以进行 geoip 编码。
但是,当使用手机和本地主机时,我得到了错误的 IP。
我尝试使用 jquery 来获取地理位置,但是我无法将 lat 和 lon 插入到网络链接中。
目前我正在使用它来克服我的问题并为另一个 API 获取 IP lat 和 lon。
$b = '192.168.1.1';
if($_SERVER['REMOTE_ADDR'] == $b)
{
$response = file_get_contents('http://www.geoplugin.net/json.gp?ip=18.252.235.89');
$area = json_decode($response, true);
}
else
{
$response = file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR']);
$area = json_decode($response, true);
};
我正在使用上面的代码来获取纬度和经度并将其插入到
http://api.openweathermap.org/data/2.5/weather?q='.$area["geoplugin_city"],$area["geoplugin_region"].'&APPID=000000
但是,这只适用于我的本地机器,不适用于移动设备,而且要获得 lat 和 lon 的工作量很大;在我看来,使用 API 获取另一个 API 信息是错误的。
我可以使用 jquery 或某种形式的浏览器位置来处理所有事情吗? 我的目标是让经纬度访问者将其放入 openweathermap.org api。
我希望我已经提供了每个人都需要帮助我的信息。
【问题讨论】:
标签: php jquery geolocation