Jul 18 2011

HTML5 Geolocation using GPS with IP-based fallback

It turns out that it is pretty easy to take advantage of the geolocation features of HTML5.  I found a great tutorial that discusses how to get the basics of geolocation working, and then adds in IP-based fallback. You can find Arman Mirkazemi’s tutorial “HTML5 Apps: Positioning with Geolocation” here.  There are a few things that are really great about this:

  1. It is very easy to get started.  The APIs seem very easy to use.
  2. Some great information is available, including longitude, latitude, altitude, accuracy of all of that position information, and GPS timestamp of when the position was measured.
  3. Most of the desktop browsers today (Firefox, Chrome, Safari) support providing positions through the geolocation APIs, providing a single solution that works on both mobile and desktop platforms.
  4. This solution provides an IP-based fallback using the YQL Geo Library in case a GPS-based position is not available, supporting a single solution for both mobile and desktop platforms.
  5. The tutorial should take no more than about an hour to complete.

Examples of the two tutorial exercises can be found here:

  • http://david.feinzeig.com/m/geo.html – Simple “find my location” app that checks every time a button is pressed. Makes call to the static Google maps API to display the current location.
  • http://david.feinzeig.com/m/geo2.html – More complicated app that monitors your position and updates when your position changes. Makes call to the static Google maps API to display the current location.