HectorMac
HectorMac

Reputation: 6143

Can iPhone web apps get GPS position?

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.

Upvotes: 18

Views: 35603

Answers (4)

Michael Muller
Michael Muller

Reputation: 11

Yes, but the accuracy is pretty bad. I just built a web form that posts GPS settings from the watchPosition() function to my database and then maped the results. While paddling down a local river it got only two of seven posts correct. The rest were outside the river, and two of those were about a mile away! I'm now looking for a better solution.

Here's the code I use to update the form fields:

<script type="text/javascript">
function getGPSLocation()
{
  if(navigator.geolocation)
  {
   navigator.geolocation.watchPosition(onGeoSuccess);
  } else {
   alert("Your browser or device doesn't support Geolocation");
  }
}

function onGeoSuccess(position) {
  document.getElementById("Latitude").value =  position.coords.latitude;
  document.getElementById("Longitude").value = position.coords.longitude;
}
</script>

And this is the form. Update to suite your needs.

<form>
<img src="spacer.gif" OnLoad="getGPSLocation();">
<input type="Text" name="Latitude" id="Latitude" value="">
<input type="Text" name="Longitude" id="Longitude" value="">
</form>

Upvotes: 1

trapez
trapez

Reputation: 51

Check out the app SendLocation under navigation by Jouni Erola.

Its a simply app that will send out the lat & lon of the iPhone to YOUR server. Simply enter your server url to receive the location as HTTP-GET methid

Upvotes: 5

Charlie Bloom
Charlie Bloom

Reputation:

I've don this without any programming. You can:

  1. Download the iPhone app "Basic GPS" from iPhone Store.
  2. Start an account at Twitter.com (if you don't already got one).
  3. Start an e-mail-to-twitter account at Twittermail.com.
  4. In Basic GPS settings use your secret e-mail address from Twittermail.
  5. At Twitter.com/widgets click "Other" to get your HTML-code for publishing your Tweets elsewhere.
  6. Put this HTML code on your homepage.
  7. In Basic GPS you just click the blue "I" (on) button, "Email" and "Send" to send your position to Twittermail, which publish it on Twitter. And Twitter will automaticly publish it on your homepage.

See a working axample at http://CharlieBloom.com. Only the 3 latest (customizeable) Tweets are visible, click on "Follow me on Twitter" to se "My position ....." and a Google Maps-link. Positions are updated on my website 2-3 minutes after I have sent them.

Best regards, Charlie Bloom

Upvotes: 1

Maciek
Maciek

Reputation: 3382

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.

Upvotes: 16

Related Questions