<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() { alert('onDeviceReady Function works');
var option = {frequency:500,maximumAge: 0, timeout: 1000, enableHighAccuracy:true};
navigator.geolocation.getCurrentPosition(onSuccess, onError, option );
}
function onSuccess(position) { alert("It Works!!!");
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude;
}
function onError(error) {
//alert(error);
alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
}
</script>
<p id="geolocation">Finding geolocation...</p>
上面的代码deviceready()
功能正常,但alert("It Works!!!");
无效。请告诉我为什么它在我的设备模拟器中不起作用?
我收到错误消息。
截图:
答案 0 :(得分:0)
将超时增加到&#39; 5000&#39;或者&#39; 10000&#39;并且还增加 maximumAge
{ maximumAge: 3000, timeout: 5000, enableHighAccuracy: true };