I have the following JS which gets the current location of the user and displays their zipcode...
(function ($, geolocation) {
if (geolocation) {
geolocation.getCurrentPosition(function (position) {
$.getJSON(
"http://ws.geonames.org/findNearestAddressJSON?callback=?",
{
lat : position.coords.latitude,
lng : position.coords.longitude
},
function (data) {
$(function () {
$('#zip').text(data.address.postalcode);
});
}
);
});
}
}(jQuery, navigator.geolocation));
Kindly helped on CodeReview, since my original code was pretty terrible, https://codereview.stackexchange.com/questions/13481/to-use-or-not-to-use-public-variables-in-javascript/13483#comment21844_13483
HTML:
<div id="zip"></div>
...which then displays the zipcode in a div.
This works fine in Mobile Safari, along with desktop Safari, but as soon I add the apple-mobile-web-app-capable
meta tag, the code breaks.
I had the code log to the console after each step, and it all ran smoothly in regular Safari and Mobile Safari. As soon as I added it to my home screen though (with the meta tag in the head), the app wouldn't even run the JS code. It didn't bother logging to the console either, which makes me wonder if location services are allowed in WebApps.
This problem also occurs if the page is reloaded while run from the home screen.
Is there anyway to fix this? Is this a common problem?