Hallelujah! Geolocation is available in the iPhone’s browser. I was thrilled to finally have this app ask to use my location. This is only true for the new 3.0 version of the browser (oddly, geolocation is *not* available in the Mac version of Safari 4). Adding the ability to geolocate users via the browser opens up a whole new range of web apps.
If you’re eager to start catering to the legion of iPhone users ready to tell you where they are, Adam DuVander (the fellow behind the Portland Wifi Finder among other things) has written up an excellent post on how to access their location. The iPhone is using the W3C Geo-Location spec. If you are running the latest version of the iPhone OS you can try it out at http://bit.ly/w3cgeo
The code itself is very simple as Adam’s sample demonstrates:
var lat = position.coords.latitude;
var long = position.coords.longitude;
alert(‘Found location: ‘ + lat + ‘, ‘ + long);
alert(‘Could not find location’);
(you can get more information on the behavior in Adam’s post)
Apple was smart about the user experience and kept the user in control. I was prompted to give Safari permission to access my location (I should only be asked this question one more time). I was then prompted to share my location with the website (in this case Adam’s test). I expect many sites to quickly update their mobile sites to include location (Google already identifies your location if you are using the Android browser so I hope they update the iPhone version of their homepage shortly).