PhoneGap version: 2.0.0. Android API level 16 (4.0.3 version). Code sample which prompts an error:
navigator.geolocation.getCurrentPosition(onSuccess, onError, {enableHighAccuracy:true});
function onSuccess(position) {
console.log('latitude: '+ position.coords.latitude);
console.log('longitude: '+ position.coords.longitude);
}
function onError(error) {
console.log('Appeared error : '+ error.message);
}
Always getting an error in emulator Failed to start Geolocation service
, error code 2
. Even if send GPS coordinates through Android console or DDMS
Android manifest permissions:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Are you testing this on the emulator only? The Geolocation Service always fails in my Android emulator but not on a real device.
EDIT: Please try using the following code
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(myPositionSuccess, myPositionError, {maximumAge: 300000, timeout:10000, enableHighAccuracy : true});
};
You need to set the enableHighAccuracy
option to true
while you are trying to get the location.
navigator.geolocation.getCurrentPosition(onSuccess, onError,{enableHighAccuracy:true});
Moreover, to specify the coordinates of your position in the emulator,
Eclipse -> Open Perspective -> DDMS -> Emulator Control -> Location Controls
Specify the coordinates of the position and press "Send" .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With