Question regarding success callback of navigator.geolocation.getCurrentPosition

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:29:25 UTC