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

Mar 11, 2013 11:55 AM in response to MikeAtNextBus

My suspicion is that one stabilty issue is the root of it all but since it is not predictable in its behaviour it may sometime seems that the problem is gone. However, I can be wrong on this and in that case I would be really happy!


travisdahl and 73Hpilo can you do me a big favour? Can you open http://jsbin.com/esasix/16/ in your phones, go outside and walk around for a bit? Do you get steady 5 or 10 accurracy levels, even after re-loading the page a couple of times? As you can see on jsbin this is really basic watchPosition code.


When I did this just now I first got great numbers as these:


count timediff distdiff accuracy

4 00:01.065 1 5

3 00:01.003 3 5

2 00:00.980 0 5

1 00:00.765 0 5

0 00:01.157 0 5


But after my forth re-loading of the page I started getting just one position then nothing, at some occation 3 signals then nothing (tried 2 different devices).

I get logging from many users with different devices in different locations for my service and from what I see there is a lot of weird behaviour on 6.1.2 as well...?


iOS 6.1.3 beta users can't talk about it but they can perhaps tell us if they think that geolocation api users have a stable future ahead of them or something ;-)

Mar 11, 2013 12:40 PM in response to MikeAtNextBus

Okay, it is a simple issue to replicate in just a few seconds. I feel it is not a safari, but an IOS issue. It’s almost as if Google wrote the bios for the IOS to meet the WC3 html geo location spec and took it with them when IOS6 kicked them off the bus.

Using an IOS device go here:


http://uc.myaesc.com/geoloctestorig.htm


  1. Click start, watch should return result almost every second.
  2. Then click the Google link to leave this page.
  3. Then user browser back button to return
  4. Click start.
  5. Watch will return 1 to 3 records and hang.


Thats it. untill it does not hang, the issue remains.


Mark

Mar 13, 2013 12:42 PM in response to MikeAtNextBus

Today was bad, nither me nor a customer of mine could get any proper data even when reopening, restarting, starting native etc. yet iPad running 5.1.1 returned perfect 5 or 10 in accuracy... I can't promote my app or service anymore due to this since most of my customers attempts fail.


I have had the usual problems with position not comming at all in some cases, getting 65 and worse in accuracy together with bad positions in other cases.

Something I have also seen quite a bit lately is steaks of returning error code 3 = TIMEOUT every second for awhile.

Another thing I have been seeing is positions going cracy in linear patterns... In the photo below the guy was standing still aproximately 100m from the blue marker at the top, when suddenly his own position started to move away as shown. Here's a section of the returned positions (nr, time, dist to blue marker, accurracy)


99 01:35.250 P 812m 448a

98 01:34.243 P 812m 448a

97 01:33.309 P 807m 448a

96 01:32.254 P 786m 433a

95 01:31.237 P 786m 433a

94 01:30.305 P 779m 433a

93 01:29.235 P 755m 418a

92 01:28.234 P 755m 418a

91 01:27.370 P 745m 418a

90 01:26.241 P 718m 402a

89 01:25.227 P 718m 402a

88 01:24.303 P 706m 402a

87 01:23.232 P 675m 386a

86 01:22.225 P 675m 386a

85 01:21.288 P 661m 386a

User uploaded file


I have seen similar logs from other users on other devices. Anyone else who have experienced results like this? The code behind this is very basic and again, the same code running iOS 5 performs perfect...


(The TDS ticket resulted in nothing, they can't look into bugs...)

(Have also contacted someone at webkit in an effort to get hold of someone with knowledge but no response so far)

Sep 27, 2012 7:47 AM in response to Ecasasin

That may be true, but it's an unacceptible solution. I really don't feel like putting this on my webapp.


"Dear Viewer, due to a flaw in iOS6, in order to play our geocaching game you have to go to settings, click around for 10 minutes fiddle with it until you get it exactly right, then you can play.... or just trade in your iPhone 5 for an iPhone 4s and it works out of the box"

Nov 14, 2012 1:10 PM in response to MikeAtNextBus

As a developer I can understand that there are bugs, but I can't believe this bug was not fixed along with 6.0.1. This is major issue for many web apps. Shame for Apple, especially now as they emphasis web based mapping solution as alternatives to their own native map app.


I filed a bug report but I guess 1000 more might make wheels rolling.


cheers,

matti

Dec 14, 2012 11:06 AM in response to travisdahl

travisdahl - I don't see the reference to latest beta in the link from your previous post


does anyone else have intel on this?


Apple: FWIW we are running a high profile environmental project that relies on this working properly - you can read about it here.


http://www.nytimes.com/2011/11/28/science/earth/nature-conservancy-partners-with -california-fishermen.html


This bug has killed our application - its a huge problem and has me trying to downgrade our existing iPads (almost impossible) and moving to Android based tablets


Matt Merrifield

GIO - The Nature Conservancy

Jan 18, 2013 7:56 PM in response to Tools Dept.

Well the fix did not work for me. Maybe I did not follow the instructions completely but I think I did and I did the initialization in the windows.load event so it was early (but maybe not early enough?).


One thing I noticed independantly of your code that I never really noticed before. After you call the

watchPosition
then the
clearWatch
does not seem to work. I run the
clearWatch
periodically when I leave my maps pages and on a non home screen version the navigation icon on the top of the phone disappears. On a home screen app (same app just bookmarked to the home screen) it never goes away. And yes I did validate that it was being called with an alert just before the statement and making sure the watchID was initialized too.


So there is still some pretty broken stuff in iOS 6.

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.