Working with geolocation
With the arrival of HTML5, one of the many new APIs and concepts introduced in the specification is the possibility to identify the location of the client that is loading the web page, through the Geolocation API (http://dev.w3.org/geo/api/spec-source.html). Of course, in the world of web mapping applications, this opens new and great possibilities.
In this recipe, we are going to show how easily we can identify the current location of the user and center the map's viewport to it:
Every time the user clicks on the Geolocation button, the map's viewport will be moved to the current user's location and a marker will be placed on it. Also, when the mouse goes over the marker, a popup with the current location will be shown.
Getting ready
As we mentioned at the beginning of the recipe, Geolocation is a feature that the browser must implement, so we need an HTML5 compliant browser to make this control work.
How to do it...
First create the HTML file with OpenLayers dependencies...