Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 702
HectorMac Avatar asked Jun 29 '09 15:06

HectorMac


2 Answers

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/
like image 131
Maciek Avatar answered Sep 22 '22 18:09

Maciek


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

like image 43
trapez Avatar answered Sep 23 '22 18:09

trapez