IOS WebApp does not allow location services?

I have the following JS that gets the current location of the user and displays his 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));

Please help with 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 great in Mobile Safari along with desktop Safari, but as soon as I add the meta tag apple-mobile-web-app-capable, the code will break.

, Safari Mobile Safari. , ( ), JS-. , , WebApps.

, .

? ?

+5
2

, - iOS, apple-mobile-web-app-capable, navigator.geolocation. , . HTML .

( apple-mobile-web-app-capable set):

navigator.geolocation.getCurrentPosition( function ( position ) {
    alert( 'yay!' );    
},
function ( error ) {
    alert( 'boo! error: ' + error.message );
} );

, , . .

} )( jQuery, window.navigator.geolocation );

, , .text() , .getJSON() :

function (data) {
    $(function () {
        $('#zip').text(data.address.postalcode);
    });
}

Try:

function (data) {
    $('#zip').text(data.address.postalcode);
}

, :

( 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) {
                    $('#zip').text(data.address.postalcode);
                }
            );
        });
    }
} )( jQuery, window.navigator.geolocation );
+1

All Articles