I'm struggling to use the maximumAge parameter in HTML geolocation. The way it works in Chrome does not seem to match the spec.
I've read through the geolocation API spec and from what I can understand, if you set the maximumAge to zero, you should always get a fresh position.
The maximumAge attribute indicates that the application is willing to accept a cached position whose age is no greater than the specified time in milliseconds. If maximumAge is set to 0, the implementation must immediately attempt to acquire a new position object. Setting the maximumAge to Infinity must determine the implementation to return a cached position regardless of its age. If an implementation does not have a cached position available whose age is no greater than the specified maximumAge, then it must acquire a new position object. In case of a watchPosition(), the maximumAge refers to the first position object returned by the implementation.
However, this is my code:
function gpsSuccess(pos) {
var positionDate = new Date(pos.timestamp);
var currentDate = new Date();
console.log(positionDate.toLocaleString(), currentDate.toLocaleString());
}
watchId = navigator.geolocation.watchPosition(gpsSuccess,
gpsFail, {
enableHighAccuracy: true,
maximumAge: 0,
timeout: 27000
});
And I'm seeing the following:
Wed Nov 23 2011 10:25:43 GMT+0000 (GMT), Wed Nov 23 2011 10:52:16 GMT+0000 (GMT)
So that's half an hour's difference between the position obtained and the current time.
I thought it might just be the difference between the satellite time and the local time, but I've been hitting refresh repeatedly, and the positionDate isn't changing, even though the currentDate is.
Why is the same, cached position being reused, even though maximumAge is set to zero?
This is in Chrome, BTW.