Getting geographical location input
One of the exciting new features in HTML5 is the geolocation API (http://www.w3.org/TR/geolocation-API/). It allows the developer to ask for the user's location. This API allows the developer to get geographic coordinates, such as latitude and longitude.
Before this API developers had to rely on more crude methods, such as GeoIP databases. These methods produced results that had poor accuracy. Depending on the user's browser, device, and the availability of GPS on it, the geolocation API could give results with a few meters accuracy.
In this recipe, we're going to display the user's location on a map. To do this, we're going to use the Leaflet library. The use of this library to show maps is covered in the Displaying a map recipe, Chapter 2, Display of Graphical Data.
How to do it...
Let's get started.
We're going to create a HTML page with a map placeholder, which will include the leaflet library (both CSS and JS files) and our code for getting and displaying...