Improving PhoneGap geolocation for Android

Reading Time: < 1 minute

Some Android devices have the problem of not being able to obtain the user’s current geolocation using the following standard code:
navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
The first possible solution to this problem is to add the following options parameter:
options = { enableHighAccuracy: true,timeout: 5000,maximumAge: 0,desiredAccuracy: 0, frequency: 1 };
If that doesn’t work, the other possible solution is to stop using getCurrentPosition and start using the following:
var watchID = null;
if (navigator.geolocation) {
     watchID = navigator.geolocation.watchPosition(
     function showPosition(position{
         navigator.geolocation.clearWatch(watchID); 
     },
     function showError(error) { },
     { enableHighAccuracy: true,timeout: 5000,maximumAge: 0,
        desiredAccuracy: 0, frequency: 1 }
     );
}