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

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.