Search code examples
androidcordovaphonegap-plugins

Phonegap geolocalization plugin


I'm developing an app through phonegap, I've add the geolocalization plugin and it's working, the problem is if I run the application through phongapp desktop the localization works, but if i compile and generate the apk the localization doesn't work. Here is the js code:

function onDeviceReady() {
        navigator.geolocation.getCurrentPosition(onSuccess, onError);
    }

    // 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 />';
    }

Solution

  • confirm!

    check the permission on platform/android/androidManifest.xml file:

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