douliang4858 2018-11-26 04:32
浏览 117
已采纳

使用PHP进行地理定位

Is there a way to get lat/long into PHP in a single file solution? Normally using JS I would use this in a pure JS sulution, but now I need the values in PHP variables:

<script>
$(document).ready(function(){
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showLocation);
    } else {
        $('#location').html('Geolocation is not supported by this browser.');
    }
});
function showLocation(position) {
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;
    return latitude;
}
</script>

I need to get the lat/long vars into PHP without using an AJAX post into a url: xxx.php type of sulution. Single file only. Any ideas on a clean way to execute this anyone?

BTW- If I write them into cookies this only works if I reload the doc. :-(

Thanks!

  • 写回答

1条回答 默认 最新

  • douruoshen1449 2018-11-26 05:40
    关注

    You can use geoplugin api Link

    <?php
      echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp? 
      ip='.$_SERVER['REMOTE_ADDR'])));
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集