The advantages of the Geolocation API

This is the second post by Mat Diss, founder,, a UK mobile Internet software company that is focused on new ways for web designers to construct better websites that can be delivered across all platforms.

In this blog, Mat, looks at the advantages of the Geolocation API…

The Geolocation API already brings with it the possibility for the user to share their location. By design, this is a user choice on a site-by-site basis – choosing to share their location when they feel they’ll benefit and when they trust the service provider. This opens web sites up to the opportunity of location base services, such as finding people or places nearby, combined with mapping services this can all help to create a more pleasurable experience with a service provider – saving time and shoe wear.

You can locate a user by including the javascript below in your page


  function getLocation() { 

    if (navigator.geolocation) {

      document.getElementById(“findMe”).innerHTML = “We’re locating you … “;


    } else{

      document.getElementById(“findMe”).innerHTML =  “Phone not supported”;



  function fail(error){ 

    document.getElementById(“findMe”).innerHTML = “Error: “+error.message;


  function success(position){

    document.getElementById(“findMe”).innerHTML = “Located you, at lat:  “+ position.coords.latitude +  ” , lng: ” + position.coords.longitude;

    var redirectUrl = ‘/map/latitude/’ + position.coords.latitude +  ‘/longitude/’ + position.coords.longitude;

    window.location = redirectUrl;


and then including a find me button like,


This example redirects the user to a new URL with the latitude and longitude populated, but you could equally do this with a AJAX call back.


Visit the demo site at:

View Video file: bemoko html5.gelocation.wmv