Geolocation does not stop in Phonegap

When i started

window.onload = function () { document.addEventListener("deviceready", getGeolocation); } function getGeolocation() { navigator.geolocation.getCurrentPosition( successCallback, errorCallback, {maximumAge: 0}); } 

or

 function getGeolocation() { watchGeoMarkerProcess = navigator.geolocation.watchPosition(updateCallback, errorCallback); } 

and then

 function updateCallback(position) { if (position.coords.accuracy < 100) { navigator.geolocation.clearWatch(watchGeoMarkerProcess); } } 

in my application on iOS 5 using phonegap it seems to be stuck because the geolocation indicator icon remains in the top bar and it never disappears, which I mean that the GPS does not turn off. Also, sometimes I don’t get any coordinates at all, throwing a timeout error.

I don’t think that something is wrong with the code, since it works fine as a webapp.

Any ideas?

+7
source share
3 answers

navigator._geo is the real implementation that I believe in. I saw how the latest git fixes where they try to drag navigator.geolocation, but apparently don't work on iOS. Looking at the source code of the phone, I was offered to use a real call instead.

Here is the git commit: http://mail-archives.apache.org/mod_mbox/incubator-callback-commits/201203.mbox/% 3C20120307000809.B82AA5D82@tyr.zones.apache.org % 3E

Here's another question: https://groups.google.com/forum/?fromgroups#!topic/phonegap/W32yYpV28W8

UPDATE: I have some success now: Change your phonegap.js, comment lines 3451-3453 that look like this: __proxyObj (navigator.geolocation, navigator._geo, ...

You will get an ugly permission warning. but the place should work. The reason for this change is that you will now use safari location rather than PhoneGaps.

UPDATE2: .. and the problem with PhoneGap turned out to be a conflict with another javascript library, in this case dragdealer.js. Therefore, double-check the names of the suspicious variables, such as "Location" or "Position", in any other JavaScript that you use. For some reason, this conflict was not a problem on platforms other than iOS.

+3
source

For what it's worth, I have the same problem and these fixes do not work. But they can for you:

  • make sure you get the location after onDeviceReady () has been called
  • try using navigator._geo.getCurrentPosition
+1
source

I had the same issue though on Android.

Adding the enableHighAccuracy option made it get started:

 navigator.geolocation.getCurrentPosition(onSuccess, onError, {enableHighAccuracy:true} ); 
0
source

All Articles