I have long been excited about HTML5 having access to a geolocation data. It should make it possible to build a whole range of applications for phones and other devices that are cross platform but make use of the users location. Unfortunately reality bites when you try and actually build an application based on the technology.
I have been working with Sencha Touch and the Ext.util.Geolocation object but am having problems with accuracy. I have noted the following behaviour.
When I call for a location on iPhone (3G) and iPad (v1) I get a one with around 1.3km accuracy. Basically it places me at one of two spots about 1km apart. If I switch to the native maps app then it places my position within 10m of where I am standing – that “wow it knows where I am” accuracy . Switch back to my web app and the first call to the GeoLocation returns similar accuracy. Any subsequent calls return the old inaccurate positions.
I have tested this briefly on Android (Google’s first phone) and have similar behaviour.
I am setting allowHighAccuracy=true and I have experimented with different age and time out durations to no effect. I have also tried calling the underlying JavaScript methods with similar results so I don’t believe it is the Touch libraries – but would welcome your thoughts.
My conclusion is that both iOS and Android only pass cell tower level location accuracy to the browser and do not ever use GPS – at least not in an urban environment. Basically enableHighAccuracy from the Geolocation API spec is ignored. Is this a correct assumption? I hope it isn’t because it effectively cripples the HTML5+GPS application market.
I wrote a test application that you can use to check this behaviour for yourself. Remember this is a mobile app. You can test it in Chrome or Safari on the desk top but will need to load it on your phone and be outside to benefit from GPS! Dink the QR Code with your phone and take a stroll if you are reading this indoors.
The application allows you to either poll the location by tapping the “Update Location” button or ask the browser to continuously update your location using autoUpdate. The maximum age parameter is hardwired to zero so any requests should attempt to fetch new location data. The time out is set to 20 seconds. You will find that if you keep punching the “Update Location” button when it isn’t returning new locations you will just get a series of time out alerts 20 seconds later.
Finally the “Show Map” button will launch the maps app on iOS devices and put a place marker on where HTML5 thinks you are. You can then compare it with where the maps app thinks you are. They are often different immediately or, after a few seconds, the maps app will move your current location to a far more accurate spot as the GPS kicks in. On Android the behaviour of the “Show Map” button is less obvious as it doesn’t always appear to open the maps app and sometimes just opens the Google Maps application. You will have to open the maps app manually.
I find it amazing that there are so many posts out there raving about location info in the browser yet when I try and use it I find it actually sucks. Maybe OK for finding your nearest Starbucks but not a lot else. If you have read The Inmates Are Running the Asylum by Alan Cooper then you will be familiar with the notion of “Dancing Bear Software” – it is amazing the bear can dance, what a shame it doesn’t dance very well!
I do hope I am doing something really really dumb here and am totally wrong. Please look at the code in my app page and tell me so.
Interesting post. I’ve been experiencing similar behavior with a Phonegap / jQTouch app for iOS. I thought it was due to updates in Phonegap, but perhaps not.
But I also tried your app just now on my Palm Pre and on my iPhone (3GS). I’m travelling on a train, and I tried the app while I’m moving, and also while stopped in a station.
On the Palm, the app worked fine. Whether I used auto update or manual, it consistently got accuracy within 30 to 100 meters. And when I checked at the station, it put the marker in the right place.
On the iPhone, it didn’t work so well. Initial accuracy was 1.4 Km, and then after a few auto updates (or manual taps) it got down to 30 to 100 meters). I also tried tapping Update Location several times, but it crashed Safari. Not sure what’s up with that.
So, I’m not sure how helpful that is, but I will keep testing and also compare code to see if anything jumps out. Thanks!
Thanks for that Steven. I’m pretty certain this is device specific stuff. And yes I had Mobile Safari crash on me a few times during testing – I should have mentioned that.
I find thatone has to use geolocation.watchPosition, and then I personally create functions to ignore inaccurate results returned by the method. It takes more than one request for it to find where you are. I would imagine both iOS and Android quickly do multiple calculations to give you your position, thats why it takes a little while.
I hope you update your page if you ever figure out your phonegap issues. This is one of the first links that pops up when I google “phonegap geolocation maximumAge”, There is a lot of research to do to figure out the quarks of working with phonegap, and I fear your page will just scare people away.
More tips: Moving or walking outside will also help it find a location much faster. If I am outside, I can normally find my location accurate to 30meters in < 10 seconds.
I feel your pain my friend, I’ve done lots of testing for my mobile HTML5 app. I don’t use any mobile framework, just the barebones geolocation method.
Adding the following will take your pain away.
{maximumAge:0, enableHighAccuracy: true}
– Collin
@Collin That doesn’t seem to solve my issues on iOS6
Am currently testing https://github.com/craftti/getAccurateCurrentPosition which looks promising.