I’m working on a webapp for iOS 4.1 (dev device).
For Geolocation I’m asking the device (via PhoneGap API) for it’s current lat and long position and then handling it over to Google.
But the $.getJSON always throws the error callback function (not in code right now).
That’s my code:
function getLocation() {
$('#location').html('asking for location...');
navigator.geolocation.getCurrentPosition(function(position) {
var url = 'http://maps.google.com/maps/api/geocode/json?sensor=true&latlng=' + position.coords.latitude + ',' + position.coords.longitude;
$.getJSON(url, function(data) {
$('#location').html('' + data.results[0].formatted_address);
});
}, function(error) {
$('#location').html('unknwon');
});
}
On Android devices this piece of code works totally fine, on iPhone the Google call doesn’t give anything back.
Is this a mobile safari problem? Because the PhoneGap API returns the position properly.
I believe you need to add
maps.google.comto theExternalHostsarray in PhoneGap.plist.