Can iPhone web apps get GPS position?

geolocation, gps, iphone, mobile-safari

Solution

Here's a snippet on how to read location from the iPhone. Looks like it requires 3.0:

 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');
 }

See: http://mapscripting.com/how-to-use-geolocation-in-mobile-safari

By the way, if you want to use web code on the iPhone, there are a couple middle-ground solutions you could try that don't force you to create a native app but allow you to wrap your site in an app and get access to GPS and other native features.

- PhoneGap: http://phonegap.com/

- Appcelerator: http://www.appcelerator.com/products/titanium-mobile/

Problem

Is there an easy way to design a website to facilitate an iphone user providing gps coordinates to the site? I am wondering if there might be a naming convention for form fields for example, to let the user input in an automated way. I am considering building a location based website and would like to tailor it for iphone (and other mobile users). I realize an iphone app could do this but I'm not equipped to create one.

Original source