Phonegap地理定位应用程序崩溃 [英] Phonegap Geolocalisation application crashes
本文介绍了Phonegap地理定位应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用phonegap javascript API获得当前的本地化.这是从phonegap网站获取的示例代码:
I'm trying to get current localisation using phonegap javascript api. Here is a sample code taken from phonegap website:
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'Altitude: ' + position.coords.altitude + '<br />' +
'Accuracy: ' + position.coords.accuracy + '<br />' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
'Heading: ' + position.coords.heading + '<br />' +
'Speed: ' + position.coords.speed + '<br />' +
'Timestamp: ' + new Date(position.timestamp) + '<br />';
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
如果我删除地理定位代码,则该应用程序运行良好.
If I remove geolocalisation code, the application works well.
有什么想法吗?
预先感谢
推荐答案
如果您在Android中看到错误,则要添加enableHighAccuracy标志:
If you are seeing the error in Android, you want to add the enableHighAccuracy flag:
navigator.geolocation.getCurrentPosition(onSuccess, onError, { enableHighAccuracy: true });
这篇关于Phonegap地理定位应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文