GPS in Safari Mobile

So… what if you wanna get the GPS position, but within a WebApp’s context?. There are several tools, such as PhoneGap, that encapsulate GPS access. But it turns out that there is an extremely easy way to accomplish this task.

Check out this JavaScript snippet… easy, right?

[cc lang=”objc”]navigator.geolocation.getCurrentPosition(foundLocation, noLocation);

function foundLocation(position)
var lat = position.coords.latitude;
var long = position.coords.longitude;
alert(‘Found location: ‘ + lat + ‘, ‘ + long);

function noLocation()
alert(‘Could not find location’);