• Print

Geolocating Your iPhone Users via the Browser

safari permission

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:

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’);

}

(you can get more information on the behavior in Adam’s post)

mapscripting permission

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).

  • http://squio.nl/blog/2009/06/09/firefox-35-does-geolocation/ Johannes la Poutre

    Interesting, looks like the same method which works for Firefox 5.5+

    Can someone with an iPhone give it a try over at my blog, here: http://squio.nl/blog/2009/06/09/firefox-35-does-geolocation/

    Ans please met me know if this works (in Android it doesn’e, there you obviously need to use the Gears implementation provided by Google).

  • http://squio.nl/blog/2009/06/09/firefox-35-does-geolocation/ Johannes la Poutre

    Sorry typo in previous post, that should read Firefox 3.5+ of course!

  • http://blog.calbucci.com Marcelo Calbucci

    The geek in me finds this very exciting. Makes you want to just build an app using geolocation.

    Kudos do Apple.

  • http://ttklf4.tempw8.internet1.de/Mobile.aspx ttklf4

    Hello,

    I hope this new Geographic Location feature of Safari on iPhone will work in my LBS application: http://ttklf4.tempw8.internet1.de/m/New1/Search.aspx

  • MSchienle

    Johannes -

    That worked fine from my iPhone 3G (2008). It prompted to use my geolocation, and provided a map of my location.

    Thanks for the post, Brady. I’m looking froward to coding up this in my sites and apps.

  • Christopher Johnston

    This is very cool and should provide some interesting results as google gets better analytics for local business listings. You could actually get good data about where users are whe searching for you. If you could then cross reference that against some billboard or signage ad placement you would not how effective some of those signs really are

  • http://blog.stewtopia.com randy Stewart

    Brady-

    You’ll be pleased to know that m.flickr.com uses geolocation via Safari on the iPhone. Very cool.

    Check it out http://blog.flickr.net/2009/06/18/nearby-on-your-phone/

    Via Daring Fireball – http://daringfireball.net/linked/2009/06/18/flickr-location

  • http://prepaid-vergleich-tarife.de/discotel/ danny

    I am wondering, since I am switching phones and am getting an iPhone I want to get some apps ready. And I am the kinda guys who does everything possible to prepare beforehand. Do you think this single app will eventually be 3.0 compatible?

  • nicky
  • http://www.der-prepaid-vergleich.de/Micro-sim/fonic-micro-sim-karte-ipad-iphone.html kenny

    That worked also on my iPhone, great post! Thanks!