How to get an accurate Geo location from Apple IPhone using navigator.geolocation.watchPosition
I’ve been messing around for a few weeks now with some emerging standards such as HTML5 and the new navigator.geolocation functionality.
I did a little reading of the navigator.geolocation standard and found another available method: navigator.geolocation.watchPosition() which after a few readings were taken, gave a much more accurate reading of my Geo location.
navigator.geolocation.watchPosition() differs from navigator.geolocation.getCurrentPosition() in that it executes a function of your choosing each time the Geo location of the device changes instead of only executing your function only once. It turns out that for the IPhone at least, this is a very important distinction.
The reason that navigator.geolocation.watchPosition() is able to give a much more accurate reading than navigator.geolocation.getCurrentPosition() on the IPhone seems to be due to the way in which the IPhone resolves it’s position, (initially at least) by GSM triangulation, which becomes progressively more accurate as more readings are taken. Thus, navigator.geolocation.watchPosition() allows the IPhone to progressively improve the accuracy of it’s Geo location reading whereas navigator.geolocation.getCurrentPosition() will return only the initial Geo location reading which in my experiments is almost always the position of the GSM tower to which your GSM connection is bound – pretty much useless in most circumstances.
It also seems that the IPhone will not engage it’s Satelite-based Geo location services in Safari, thus we have to make do with GSM triangulation positioning. This typically resolves my position to an accuracy of 15 to 20 metres in my experiments.
So…in summary, to obtain accurate Geo location positioning on an IPhone in Safari, use navigator.geolocation.watchPosition() rather than navigator.geolocation.getCurrentPosition(), simple!
I have a working example of navigator.geolocation.watchPosition() which works on IPhone for your viewing pleasure!