There's a cool new thing in web browsers: the Geolocation API. It lets web pages ask your computer where you are right now. It's easy to program with and already works on the iPhone and Firefox 3.5.

Try out WikiHere, a demo I built. Load the page, give it permission to read your location, and you should get a list of Wikipedia pages near where you are right now. It works great on the iPhone. It works slowly on Firefox and thinks I live at my ISP. Google Chrome, Safari, and MSIE don't support the API yet, although the Gears plugin does.

I'm excited by location-aware applications. Modern cell phones have great web browers and know my location. Now any web page that I trust can give me results specific to where I am. Yelp restaurant reviews, Google Local nearby businesses, tourist siteseeing, Flickr photos, nearby friends to meet with.. All of these location-aware products can now be built easily right into a webapp.

It's a pretty simple API for a Javascript programmer to work with. Basically you call navigator. geolocation. getCurrentPosition() and you get back your current position, heading, speed, and accuracy. There's support in the API for multiple samples, caching, etc. It's complete enough it looks like you could make a GPS tracker all in Javascript.

Credits: I cribbed off of Ian Walsh to figure out how to use the Geolocation API. Wikipedia lookup comes from Geonames and its fantastic API, insecurely crammed into the page via JSONP so that I don't have to host any sort of server myself. Thanks to the ubiquitous jquery library for Javascript sanity. And a hat-tip to the GeoPedia iPhone app for the inspiration; it's cool that with this new API you don't need a native app at all to build this kind of function.

tech
  2009-07-21 01:31 Z