mr.*_*r.x 3 html javascript geolocation
我尝试了这段代码:
<!DOCTYPE html>
<html>
<head>
<title>Location Location Location</title>
<script type="text/javascript" charset="utf-8">
var watchID = null;
// PhoneGap is ready
//
function f() {
// Update every 1 ms seconds
var options = {enableHighAccuracy: true,timeout: 5000,maximumAge: 0,desiredAccuracy: 0, frequency: 1 };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var xmlhttp;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
var str = 'Latitude: ' + position.coords.latitude + '<br>' +
'Longitude: ' + position.coords.longitude + '<br>' +
'Timestamp: ' + position.timestamp + '<br>' ;
var url = "load.php";
var params = "data="+str;
xmlhttp.open("GET", url+"?"+params, true);
document.body.innerHTML += str;
document.writeln("line 33");
xmlhttp.send();
//document.writeln("send");
//document.writeln(str);
}
// clear the watch that was started earlier
//
function clearWatch() {
if (watchID != null) {
navigator.geolocation.clearWatch(watchID);
watchID = null;
}
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
</head>
<body>
<p id="geolocation">Watching geolocation...</p>
<button onclick="f();"> Watch</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
你可以看到我添加了
var options = {......, frequency: 1 };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
Run Code Online (Sandbox Code Playgroud)
但当且仅当我进入选项卡并退出并输入 agin 时,我才会得到新结果。
我能做些什么?
| 归档时间: |
|
| 查看次数: |
21140 次 |
| 最近记录: |