Reputation: 1
I try to get get coordinates using geolocation on android emulator on phonegap platform. but it seems to not work. The code should be right, I add permission in manifest, use the highacuracy tag, how can I address this problem? Thanks !
<!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>
Upvotes: 0
Views: 2628
Reputation: 4978
What version of the emulator are you using? If you are using 2.3.x, be aware that geolocation doesn't seem to work: http://code.google.com/p/android/issues/detail?id=13046
You have to go down to 2.2.
Upvotes: 0
Reputation: 1351
Have you set the location in the simulator?
e.g:
$ telnet localhost 5554
$ geo fix -4.2 55.85
Upvotes: 1