cordova-plugin-geolocation: watchPosition is deranged!

129 views
Skip to first unread message

Pete

unread,
Oct 18, 2016, 3:11:28 PM10/18/16
to phonegap
I'm starting to think this plugin is seriously broken!

Plugin version 2.3.0
CLI 6.2
XDK 3619
iOS 9.3


function watchPosition(callback)
{
 
// edited for brevity
 
if(typeof callback === "function")

    watchID
= navigator.geolocation.watchPosition(callback, locFail, {maximumAge: 1000, enableHighAccuracy: true });
}

function clearWatch()
{
   
// turn off the watch

    navigator
.geolocation.clearWatch(watchID);
    alert
("Watch cleared");

}


Then I call it like this:

    watchPosition(function(p){
     
// add a loop counter to see how many times this gets called
      loopCnt
++;
      $
('#unreadAlerts').html(loopCnt);
      $
('#ajLatitude').val(p.coords.latitude);
      $
('#ajLongitude').val(p.coords.longitude);  
   
});


The answer is 3!

iPhone or iPad it gets called 3 times!

When I set the timeout value (I've tried 4000-15000) it loops 3 times and then times out.

I'm pretty sure this is not normal behavior.... does anyone have any suggestions besides rebooting (I've tried that a dozen times).

Thanks.

Pete

Kerri Shotts

unread,
Oct 19, 2016, 9:35:42 AM10/19/16
to phonegap
So, the timeout parameter specifies the maximum time allowed to send a new position object. If no new position object is sent within the timeout period, the timeout error is raised.

You have very little control over how often your device sends position updates. Generally these happen (fairly) frequently, but if you're not moving a lot, I wouldn't be surprised if at some point the device doesn't send a new position update within the timeout period. I'm just guessing on that; I haven't had time to fully test that theory.

Furthermore, receiving a timeout won't cancel the watch, so you may receive multiple timeouts in a row. Assuming you have a position report available, I would probably just treat a timeout as "no position update" and continue to use the previous position until you get a new one.

That suggests the following to try with your devices: Try taking a walk with your device and see if you get position updates after the initial 3. 

You might also try removing the plugin and using HTML5 geolocation to see if there is a substantive difference in how it behaves.

On Tuesday, October 18, 2016 at 2:11:28 PM UTC-5, Pete wrote:
...

Phil Petree

unread,
Oct 19, 2016, 11:51:33 AM10/19/16
to phon...@googlegroups.com
Actually, the watchPosition should give constant updates... by constant at least once every second. This plugin doesn't do that. It doesn't matter how much walking one does... three rapid fire updates and then nada... take a stroll, ride in the car, take a plane... three updates and then nada. :-)

In fact, if you use getCurrentPosition and lay the device on a table and poke the button once every second or so you will never get the same values. The device is constantly recalculating even though its not moving which implies (to me) that watchPosition should also be constantly recalculating.

Removing the plugin... under Android, the plugin essentially does nothing other than add in the correct permissions. Under iOS it's a different story which is why I posted this as an iOS problem.

Under my current project I can use getCurrentPosition but watchPosition would add some user-friendliness and some "oh wow!"  factor to one key management screen.  On my next project, this will be a required feature and a issue.

As always, thanks for your help Kerri!


--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to a topic in the Google Groups "phonegap" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phonegap/GfrGzd7_3WM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phonegap+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages