krasnoff
krasnoff

Reputation: 967

Error in Phonegap navigator.geolocation.getCurrentPosition

When I try to get my geographical position in my HTML page I get the following error: Error code: 2 Error message: The last location provider is no longer available here is my code:

// onSuccess Callback
//  This method accepts a `Position` object, which contains
//  the current GPS coordinates
//
var onSuccess = function(position) {
   };

var HospitalsRecord = [];



//onError Callback receives a PositionError object
//
function onError(error) {
   alert('code: '    + error.code    + '\n' +
         'message: ' + error.message + '\n');
}

// Cordova is ready
//
function onDeviceReady() {
    navigator.geolocation.getCurrentPosition(onSuccess, onError, { maximumAge: Infinity, timeout: 15000, enableHighAccuracy: true });

}

// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);


</script>

why is it happening?

thanks in advance

Kobi

Upvotes: 3

Views: 3824

Answers (2)

HischT
HischT

Reputation: 953

Try adding this to your config.xml, which is located in the root of your application:

<gap:plugin name="org.apache.cordova.geolocation" />

This could be added anywhere within the widget tag. It helped for me.

Upvotes: 2

Janmejoy
Janmejoy

Reputation: 2721

Try like this..

<script type="text/javascript">

        // Wait for Cordova to load 

        document.addEventListener("deviceready", onDeviceReady, false);

        // Cordova is ready      

        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 />' +

                            'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +

                            'Heading: ' + position.coords.heading + '<br />' +

                            'Speed: ' + position.coords.speed + '<br />' +

                            'Timestamp: ' + position.timestamp + '<br />';

        }

        // onError Callback receives a PositionError object     

        function onError(error) {

            alert('code: ' + error.code + '\n' +

              'message: ' + error.message + '\n');

        }

    </script>

For more information..

try this

Upvotes: -1

Related Questions