The advantages of the Geolocation API

This is the second post by Mat Diss, founder, bemoko.com, 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 … “;

      navigator.geolocation.getCurrentPosition(success,fail,{enableHighAccuracy:true,maximumAge:600});

    } 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.

brightcove.createExperiences();

Visit the demo site at: http://bemoko.com/html5demo/i

View Video file: bemoko html5.gelocation.wmv

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchCIO

SearchSecurity

SearchNetworking

SearchDataCenter

SearchDataManagement

Close