Phonegap Geolocation not working

  1. Make sure youryou installed the geolocation plugin (run phonegap local plugin add org.apache.cordova.geolocation), and that GPS is enabled in the device.

  2. Add a timeout and set enableHighAccuracy:

    navigator.geolocation.getCurrentPosition(onSuccess, onError, {timeout: 10000, enableHighAccuracy: true});
    

    In certain emulators you need to set enableHighAccuracy to false, so try that if still doesn't work.

  3. If you are using an Android emulator, it doesn’t read GPS values, so we need to send them via command line. We need to start a telnet session in the port that the emulator is running (you can check the port in the emulator window title, the number at the beginning, in my case 5554):

    telnet localhost 5554
    

And then run the command

    geo fix -122.4 37.78

If you close the app you need to re-send the geolocation, so if it doesn’t work, just run the geo fix command just after opening the app, before the timeout event fires.


Actually it is working, however the location cannot be determined in a short time so neither can it be deemed as success nor fail, and thus no action is performed.

This can be managed by setting a time-out for the callback of GeoLocation


When there is a phonegap feature not working, check if the corresponding permission in the app is set. e.g for internet access, or geoposition on an android-device your AndroidManifest.xml must contain following lines:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />