Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phonegap geolocation doesn't work

went according to this guide Phonegap Geoloactaion and got this code eventually(android):

<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></script>
<script type="text/javascript" charset="utf-8">


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

// Cordova is ready
//
function onDeviceReady() {
jQuery(window).ready(function(){
    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>
</head>
<body>
<p id="geolocation">Finding geolocation...</p>
</body>
</html>

and it's stuck on the "Finding geolocation..." message. usually when apps want to use my location they ask to turn on GPS and you can see a little icon on the notification bar that clarifies that it turned on and searching for GPS but this doesn't seem to happen to my code. EDIT: I tried the geolocation.watchPosition Full Example and because it has a timeout it alerts me with a timeout, so I guess he tries to find my coords but fails too, Why is that? Maps and other nav app work fine

like image 251
alexkun4 Avatar asked Dec 27 '22 08:12

alexkun4


1 Answers

Did you put

<feature name="http://api.phonegap.com/1.0/geolocation" />

on your config.xml file?

for more information on config.xml file in PhoneGap check this page

like image 196
undefined Avatar answered Jan 02 '23 02:01

undefined