Telephone geolocation not working

went according to this Phonegap Geoloactaion guide and got this code in the end (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 heโ€™s stuck in the message "Search for geolocation ...". usually when applications want to use my location, they ask you to turn on GPS, and you can see a small icon in the notification panel that explains that it is turned on and looking for GPS, but this does not look like my code. EDIT: I tried the full geolocation.watchPosition example, and because it has a timeout, it warns me about a timeout, so I think it is trying to find my coordinates, but it also fails. Why? Maps and another navigation app work fine

+4
source share
6 answers

You put

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

in your config.xml file?

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

+4
source

Are you testing your emulator?

If so, then you need to push the coordinates manually by going to Eclipse โ†’ DDMS โ†’ Emulator Control and send the location coordinates there.

Also check if the settings on your device have enabled location services.

+3
source

I had this problem. Once she worked, and the next day she stopped working. When it worked in a restarted phone

+1
source

When GPS is working

In a telephone bundle, the application will not ask you to enable gps, you must do this manually. In addition, you can provide some options, for example

 var config = { enableHighAccuracy: true, timeout: 20000, maximumAge: 18000000 } 

Thus, you will receive a callback with an error at the time of the timeout and when the geolocation cannot determine your position. You should just debug your problem and see how the error callback returns.

  navigator.geolocation.getCurrentPosition(onSuccess, onError, config); 

If it does not work

In your case, gps will not start. I can not say very much about this problem, because you only provided the html5 code. One thing I could imagine was that you are missing the cordova.js file.

For better testing and debugging, use the Ripple emulator https://chrome.google.com/webstore/detail/ripple-emulator-beta/geelfhphabnejjhdalkjhgipohgpdnoc

It emulates webapps and even has a mocker geolocation. This way you can better debug your problem because you can view the web console.

+1
source

I know this is outdated, but I noticed that for GPS to work in PhoneGap applications you need to โ€œagreeโ€ to share your location with Google.

When I did not agree before, there will be from time to time.

+1
source

When loading jQuery remotely; can you check if it is loaded? For example, if you put alert () in an onload handler, is it displayed?

 function onDeviceReady() { jQuery(window).ready(function(){ alert("jQuery ready"); navigator.geolocation.getCurrentPosition(onSuccess, onError); }); } 

If you do not see a warning message, you may need to check your "res / xml / config.xml" to see if the "access source" is configured correctly (for example, using a template)

 <access origin="*" /> 
0
source

All Articles