W3C home > Mailing lists > Public > public-geolocation@w3.org > January 2010

Re: Question regarding success callback of navigator.geolocation.getCurrentPosition

From: Doug Turner <w3c@dougt.org>
Date: Tue, 5 Jan 2010 00:46:16 -0800
Cc: public-geolocation@w3.org
Message-Id: <0FA3EA93-2D52-4748-8793-1BD6FD0A9F6C@dougt.org>
To: Advance India <advance.india@gmail.com>

1) getCurrentPosition should only call the success or failure callback once.  If it does more than this, file a bug against the implementation (if it is firefox, please cc me)

2) asking twice is up to the implementation.  I think firefox asks every time the getCurrentPosition or watchPostion is invoked.

3) assuming that (1) is a bug you found, then yes -- it would "jinx" up stuff.  

4) not sure, probably a bug.  file it, add your test case.  that would be most helpful!

5) not wrong. why do you want both a get call and a watch call?  Could you do something like:

navigator.geolocation.watchPosition(updateLocation,
                                    handleError,
                                    {  maximumAge:0,
                                       timeout:30000,
                                       enableHighAccuracy:true
                                    });
function updateLocation(position) {
  if (!setup) setup_stuff();
   // code to update map
}



On Jan 4, 2010, at 1:29 PM, Advance India wrote:

> Hi Guys,
> 
> I went to #geolocation @ irc.w3.org about this and the folks there redirected me to this email for my question(s). The shortened JS code that I use is:
> 
> gl = navigator.geolocation;
> gl.getCurrentPosition(createMap, handleError, {maximumAge:0, timeout:30000, enableHighAccuracy:true});
> 
> function createMap(position) {
>     console.log('createMap');
>     coordsListener = gl.watchPosition(updateLocation, handleError);
>     // some code to set up the map (gmap, cloudmade, etc). ideally supposed to be executed once.
> }
> 
> function updateLocation(position) {
>     console.log('updateLocation');
>     // code to update map
> }
> 
> Now my questions are:
> 
> 1) Sometimes createMap(), which is the success callback of getCurrentPosition(), fires twice, as opposed to the single execution that is expected. Is this the natural behaviour? If yes, would that be something related to accuracy? In gears geolocation API spec, it is explicitly mentioned that the success callback would be fired once and only once.
> 
> 2) In conjunction to issue #1, the browser asks user permission to share location, twice. I guess that would be related to createMap() being executed twice.
> 
> 3) The firing of callbacks are asynchronous. So in my firebug console, I get - "createMap, updateLocation, createMap, updateLocation, updateLocation, updateLocation and so on'. createMap being fired after updateLocation (watchPosition's callback) would also jinx up some code which is meant to be executed in a particular sequence.
> 
> 4) Again, is this an expected behavior? Or could it be a buggy implementation of geolocation API in FF?
> 
> 5) Am I doing something wrong? Is it like getCurrentPosition() is not necessary when using watchPosition()?
> 
> 
> Best regards,
> Dhaval
Received on Tuesday, 5 January 2010 08:46:44 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:50:58 UTC