Modern browsers and geolocation

If and only if you are using modern web browsers (I mean the latest versions of Firefox, Safari etc.) you may use the functionality of geolocation, which will give you an opportunity to show the current location of the hosting device in your application. Yes, this works even without GPS.

The geographic position information is provided using World Geodetic System coordinates (WGS84) and therefore you have to convert it into your local coordinate system in case you have a national maps with national coord sys (like ETRS-TM35FIN). This coordinate conversion we will cover later on.

The specification itself comes from W3C and I would say, it is pretty easy to use.

A simplified snippet how to enable your current location (and showing/using OpenLayers) below:

navigator.geolocation.getCurrentPosition(function(position) {
var lonLat = new OpenLayers.LonLat(position.coords.longitude,
new OpenLayers.Projection(“EPSG:4326”), //transform from WGS84
map.getProjectionObject() //to Spherical Mercator Projection

Give a try from this link, it will center the map to your current location. Obviously you have to use a “modern” web browser with HTML5 capabilities.

Written and submitted from Helsinki, Finland.