android phonegap地理位置模拟器
问题描述:
我尝试在phonegap平台上使用Android模拟器上的地理位置获取坐标。但它似乎不起作用。代码应该是正确的,我在清单中添加权限,使用高清标签,我该如何解决这个问题?谢谢 !android phonegap地理位置模拟器
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<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,{ enableHighAccuracy: true });
}
// 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>
</head>
<body>
<p id="geolocation">Finding geolocation...</p>
</body>
</html>
答
您是否在模拟器中设置了位置?
e.g:
$ telnet localhost 5554
$ geo fix -4.2 55.85
答
您正在使用什么版本的模拟器?如果您使用的是2.3.x,请注意地理位置似乎不起作用:http://code.google.com/p/android/issues/detail?id=13046
您必须下降到2.2。
在模拟器中设置地理位置如下,在eclipse中转到DDMS并选择模拟器设置的经度,经度enter image description here – Arivu 2013-06-25 10:47:01