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

Question regarding success callback of navigator.geolocation.getCurrentPosition

From: Advance India <advance.india@gmail.com>
Date: Tue, 5 Jan 2010 02:59:33 +0530
Message-ID: <59eb40fc1001041329r3a022ba9sb8b535d458a0cf18@mail.gmail.com>
To: public-geolocation@w3.org
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,

function createMap(position) {
    coordsListener = gl.watchPosition(updateLocation, handleError);
    // some code to set up the map (gmap, cloudmade, etc). ideally supposed
to be executed once.

function updateLocation(position) {
    // 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

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,
Received on Tuesday, 5 January 2010 08:29:25 UTC

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