geolocation doesn't work with iOS 6 web apps!

The javascript geolocation service doesn't work with iOS 6 web apps. We have a web app that works fine in iOS 5 and it works fine in iOS 6 in Safari. But in iOS 6 if you create a web app by adding clicking on the middle icon at the bottom of Safari and adding the app to your home screen it doesn't work anymore. The geolocation call simply hangs.


I created a really simple test problem. Simply go to http://stroll.nextbus.com/webkit/test.jsp in Safari to try it out. Then create a Home Screen icon for it and click on the icon and you can see that your position is never displayed. You can look at the html to understand this trivial application.


So how does one contact Apple to get them to investigate this issue?


And by the way, we have already gotten a huge number of complaints about this problem!


-- Mike

iPhone 4S, iOS 6

Posted on Sep 19, 2012 8:50 PM

Reply
Question marked as Top-ranking reply

Posted on Dec 22, 2012 12:01 AM

I have found a workaround for this. It turns out that you can implement the functionality of watchposition by repeatedly polling navigator.geolocation.getCurrentPosition. Set maximumAge to 0 so that you don't get a cached result. This should keep the GPS "hot".


In my implementation, function getLocation sets everything up (including saving a global callback function) and ends by calling getLocation0. Helper function getLocation0 has a single line that calls navigator.geolocation.getCurrentPosition, with getLocation1 as the immediate callback. This third function, getLocation1, checks to see if the accuracy is within the specified threshold or if we are past the specified timeout. If either of these conditions is true, we are done. Otherwise, we set a timeout that will go to getLocation0 after a specified time period, such as 500 ms.


This is simplified from code that is considerably more complex, and it is likely that I have broken it in the process, but hopefully you can get the general idea and adapt for your own use.


geolocate = (function () { // PRIVATE var lat, // Current latitude ***, // Current longitude acc, // Most recent accuracy reading callback, // Call this external function after updating location thresh, // accuracy threshhold for watchPosition, in meters giveUp; // Time at which to quit trying to get a more accurate geolocation reading // This function is called to report any geolocation errors we may get from our requests function displayError (error) { // Display error and cancel watch, if applicable alert ('Geolocation error [code=' + error.code + ', message="' + error.message + ']"'); }; // PUBLIC var geolocate = {}; geolocate.lat = function () { return lat; }; geolocate.*** = function () { return ***; }; geolocate.getLocation0 = function () { navigator.geolocation.getCurrentPosition( geolocate.getLocation1, displayError, {enableHighAccuracy:true, maximumAge:0} ); } geolocate.getLocation1 = function (position) { var now = new Date(); if (Math.round(position.coords.accuracy) <= thresh || now >= giveUp) { // display.message('Got it! Accuracy = ' + Math.round(position.coords.accuracy) + 'm'); lat = position.coords.latitude; *** = position.coords.longitude; acc = position.coords.accuracy; callback(); // Success! Now do whatever we were supposed to do next } else { setTimeout(geolocate.getLocation0, 500); timeLeft = Math.round((giveUp.getTime() - now.getTime()) / 1000), // display.message('Accuracy = ' + Math.round(position.coords.accuracy) + 'm; ' + timeLeft + 's left'); } } geolocate.getLocation = function (hook, accuracy, timeout) { if (navigator.geolocation) { // Process parameters and initialize variables callback = hook; giveUp = new Date(); giveUp.setTime(giveUp.getTime() + timeout*1000); // Give up after 'timeout' seconds geolocate.getLocation0(); } }; return geolocate; }() );


Example call:

geolocate.getAccurateLocation(myFunction, 50, 10);

71 replies

Feb 7, 2013 1:43 AM in response to aesculus

Well then, it seems I need to build a test app from scratch, maybe there are some side effects in my actual app. But the code for that app ran just fine on iOS5 and still does on other mobile OSes ...


But this comment in the above mentioned approach makes me wonder if this isn't some sort of twisted timing issue which popped up only in iOS 6 after all ...


"make this setTimeout delay one second longer than your watchPosition() timeout"

Mar 11, 2013 10:31 AM in response to msuper69

I posted on this forum a few months ago when when watchPosition wasn't updating correctly in a chromeless web app saved to your homepage from safari (worked fine IN Safari). Since the last 2 IOS point releases it has worked fine. The issue seems to have been fixed. Now while driving, it continuously updates my position.


I think this thread has become convoluded with different issues that are all related due to the fact that they use geolocation. As far as I can tell the issue this thread was created for has been fixed. At least on my iphone5.


I agree with 73Hpilo.

Mar 11, 2013 1:06 PM in response to alstorp

Tried your simple app now alstorp... im actually indoor to make it even more interesting... refreshed your page 10 times with Safari as the only application running on iPad 2 with iOS 6.1.2. No other maps or anything else in the background. Watch returns good points indicating accuracy 5 to 10 and correct location on the map. I aborted each test at 100 good returns. This is exactly the same experience i have with my own application - everything changed after i updated from an early iOS 6 to iOS 6.1.2...

I even tried my application driving through some tunnels in Norway, testing the error catching functions and it responded correctly; GPS signal lost, reverting to other means of getting approximate position. Immediately when getting out of the tunnel, the app resumed tracking with accurate positions without any user intervention at all.


I really cant say that my initial problem persist anymore.


Just as a footer, i left my iPad running your app one last time, and it has now passed 500 good returns with a rate of 1 pr sec...

Mar 11, 2013 3:24 PM in response to MikeAtNextBus

Thanks 73Hpilot! That was very interresting...


Did a few more tests, every time walking back and forth outside the house:

(the script simply logs watchPosition responses for those that have not looked at it)

1. Tested an iPad1 running 5.1.1, reload 10+ times and no problems as expected.

2. Closed all apps and all pages on my iPhone 4S running 6.0.1 and rebooted. Worked 3 reloads then I got 3 pos, 1 pos a few more etc. all the time. Each time I closed Safari and re-opened the positions started coming again (this often fixes the problem but not all the time according to my experience)

3. Tested on my girlfriends iPhone 4S running 6.1.2, closed all apps & pages and rebooted. Already on 2:nd reload I only got 1 position, then similar results 1 or a few positions, always restarted after reopening Safari.

Tried turning off wifi, but got exactly the same behaviour.

Example of a typical testresult after page refresh:

2 00:00.431 11 65

1 00:00.181 4 165

0 00:00.709 0 65

...got 3 positions then nothing...


mark00153, tested you page and got exactly the same result as above. Positions stopped as you describe and as I experience above, restarted if I reopened Safari. This was as expected as both our test run very basic code.


So, now to the interresting part: what is different in 73Hpilot and my tests? Here's what I can think of:

* We obviously have different hardware

* We are at different pysical positions meaning different satellites etc. (I am in Sweden)

* I was walking back and forth outdoors, 73Hpilot was indoors (being still?)

anything else?


I tested indoors sitting still and then I could actually refresh the page > 10 times with continous positions (I think I have read that if the GPS chip does not detect enough differences in signals it returns the previous position....?)

73Hpilot, it would be very interresting to hear what results you get if you go outside and walk while doing the tests...?


Anyone else who can try testing? travisdahl?

Mar 12, 2013 3:37 AM in response to alstorp

I just tested http://jsbin.com/esasix/16/ :


After a couple of page reloads, updating stopped with the dreaded 165 accuracy. At this point, I backgrounded Safari, started MotionX GPS, which promtply acquired a sigal with 10, accuracy, switched back to Safari and it continued updating. This is exactly the same behavior as with my test app - which btw works flawlessly on non iOS devices and on iOS < 6.

Mar 12, 2013 7:08 AM in response to MikeAtNextBus

So... Native apps always return correct positions (for me and, I assume, for all others). This means we have some low level hardware api that seems to report correct positions to the native CoreLocation.framework.

In the browser something goes wrong somewhere between this low level api and the javascript geolocation api we use. Some internal state, buffering, calulation code or whatever is buggy and messes things up.


Anyway, an interresting thing to know would be if the geolocation code is made by apple themselves or if they get it from webkit and only port it to their hardware layer? If they get it from webkit then is it possible for us to get hold of someone with inside knowledge about this issue? Should we perhaps file a bugrequest in Bugzilla?

If we get hold of the right person assigned to this bug then perhaps we as a community can help with input (and/or perhaps also put some pressure on getting it fixed...)?

Mar 25, 2013 3:37 AM in response to MikeAtNextBus

This issue has not been fixed in 6.1.3. Upgraded and tested on two devices. I only get good 5/10 accuracy for short periods on few occasions but most of the time I get faulty positions (with accuracy 65 or worse) or I don't get any signals at all = same as before. Logs for my application now shows that close to 100% of iPhone users fails when geolocation is used to track their position in Safari...

Test using http://jsbin.com/esasix/16/ and share your results (note, test multiple times doing refreshes and open/close of browser).


I've not heard anything from Apple in response to my bug-report. Has anyone received any response? Have they acknowledged the problem? Will it be fixed next month or next year? As I see it this has been a serious problem since the September release of 6.0.


Unfortunately it seems that the number of developers using browser based tracking (geolocation.watchPosition) in real applications is not large enough for Apple to address this problem.

They of course prioritise all their bugs and weigh the benefit of fixing them against the risk of compromising stability and whether they should put recources on fixing bugs in existing versions or working on the next one. I suspect they are very restrictive on which bugs they allow to be fixed in minor version upgrades which can mean we have to wait until 7.0 (September?) or longer...?


If only Apple would talk...

Sep 25, 2012 4:05 AM in response to MikeAtNextBus

MikeAtNextBus, Thanks for posting your test page. We are having the same problem.


I saved your test page to my iPhone 5 / iOS 6 home page. I launched it many times. 50+.


I received the following (good message) 66% of the time.


Here is the content:

Got position lat=xx.xxxxxx ***=-xx.xxxxxx timestampt=xxxxxxxxxxxx


I received the following (bad message) 34% of the time.


Here is the content:

initial content


Has anyone made any progress on this? Apple?


Is there a ticket open?

Oct 26, 2012 9:22 AM in response to MikeAtNextBus

I am having what I think is a similar problem - I'm not a developer so I will not get the technical terminology correct but here's what I'm expiriencing


we have an HTML5 app that is using the geolocation api

the app is meant to run on an iPad

that app has been saved to homescreen

it has a function that allows the user to click a button and return location and time

the first time user clicks it works

the second time it just hangs with spinning wheel


if I restart the app - same thing, first time fine, second time just hangs


I can replicate the problem on safari 6.0.1 on OSX 10.8.2 on a MBP


I'm pretty sure my location settings "e.g. localization" from other posts are correct in iOS


-Matt

Nov 27, 2012 5:14 AM in response to MikeAtNextBus

Same issue here 😟 (which is a bummer for my project pocket-locator.com)


I did this script which use watchPosition and i have no problem on

- iPad iOS5 browser & standalone

- iPhone4 iOS5 browser & standalone

- Blackberry Torch OS7 browser

- Blackberry Curve OS7 browser

- Blackberry PlayBook OS2 browser

- Galaxy S2 OS4 browser

- Nokia Lumia 920 wp8 browser

- iPhone4 iOS6 browser

- Safari OSX

- Firefox OSX


The only issue comes from iOS6 standalone mode.

Test URL : http://www.hello-gurus.com/labs/geoloc.html

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

geolocation doesn't work with iOS 6 web apps!

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.