31 August 2010

Location Aware OpenStreetMap

As I mentioned in a previous post, I've been tinkering with OpenStreetMap and OpenLayers, mostly so that I can host walking and cycling routes and geographical photos easily.

As a bit of an experiment, I decided to have a bash at using the W3C geolocation API to mark up the viewer's current location on the map. With a bit of tinkering, I think I've made something fairly usable.  Clicking the "show location" check box should centre the map at your current location and show a blue circle there, if you are using a browser which supports geolocation (which is pretty much any up to date browser, other than Internet Explorer).  The circle will move and the map re-centre if you move to a new location.

It probably doesn't do anything which isn't available elsewhere, but it's got several features I quite like:
  •  As you move, the map shows a breadcrumb trail of black dots marking your last ten location readings.  It shows your direction of travel in a way that I prefer to the arrow which is used by most other maps, as the occasional inaccurate reading doesn't result in a completely inaccurate indication.
  • The title of the page changes to indicate how accurate the calculation of your location is, in metres.
  • There are a number of map base layers to choose from, including maps aimed at cycling, hiking and skiing.
  • The layout is set to vary if the map is viewed on a mobile device, so that it fits the screen neatly.
  • In terms of privacy, although your browser will ask if you want to share your location with my website, as the code is written in client-side Javascript, your location is never sent to my server.
As with most Javascripts I produce, it's a continual work in progress, so feel free to leave any questions, suggestions or feedback.

No comments: