我想利用html5地理位置,并利用php的经度和纬度。如果用户允许给出其位置信息,则需要调用该功能。我想通过获取此页面的信息来部分刷新页面:
example.php?latitude = xxxx&longitude = xxx
我已经知道如何使用以下页面刷新div:$('#test_content')。load('example.php);
但是我如何以这种方式工作
<script>
getLocation();
$('#test_content').load('example.php?latitude=' + position.coords.latitude);
</script>
我的JavaScript非常糟糕,这就是我的大问题。
我知道我犯了很大的错误,但我不知道该怎么办。这是我用于地理位置的代码:
// JavaScript Document
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition,showError);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
x.innerHTML="Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML="User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML="The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML="An unknown error occurred."
break;
}
}
对于您的脚本,您需要删除第一个脚本的这些行- $('#test_content').load('example.php?latitude=' + position.coords.latitude);
并在showPosition
函数中插入int,而不是在函数括号之间插入的所有其他内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句