首页 > 解决方案 > 使用 PHP 进行地理定位

问题描述

有没有办法lat/long进入PHP单个文件解决方案?通常使用JS我会在纯JS溶液中使用它,但现在我需要PHP变量中的值:

<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>

我需要在不使用帖子的情况下将lat/long vars 放入url: xxx.php 类型的 sulution。仅限单个文件。关于以干净的方式执行此操作的任何想法?PHPAJAX

顺便说一句-如果我将它们写入 cookie,这仅在我重新加载文档时才有效。:-(

谢谢!

标签: javascriptphpgeolocation

解决方案


您可以使用 geoplugin api 链接

<?php
  echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp? 
  ip='.$_SERVER['REMOTE_ADDR'])));
?>

推荐阅读