javascript - 使用 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/lon
g vars 放入url: xxx.php 类型的 sulution。仅限单个文件。关于以干净的方式执行此操作的任何想法?PHP
AJAX
顺便说一句-如果我将它们写入 cookie,这仅在我重新加载文档时才有效。:-(
谢谢!
解决方案
您可以使用 geoplugin api 链接
<?php
echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?
ip='.$_SERVER['REMOTE_ADDR'])));
?>
推荐阅读
- reactive-programming - 是否可以将任意多个定时 Flux 合并为一个?
- django - DRF:如何获得选择的详细名称?
- html - Bootstrap 3.0.3 词缀 - 内容不在固定位置并移动到其他内容之上
- c# - 无法在 .net 核心中使用 WCF WSHttpBinding
- c++ - 可变参数模板:整数参数到 lambda 的完美转发
- python - Python3修剪关联数组中的所有数据
- firebird - 将 .DBF 文件迁移到 Firebird 2.5:如何使用不同 DBRMS 的 UNION 创建查询
- angular - HighChart中没有Y轴的散点气泡图
- html - 在 IOS 设备上,固定元素在滚动时被下部元素覆盖
- python - 如何更改字符串的替代字母的大小写