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'])));
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?