Image

Get current Location using Jquery

Hi Friends,

Below coding for get current geolocation using Jquery

 function getLocation()
  {
  if (navigator.geolocation)
    {

    navigator.geolocation.getCurrentPosition(showPosition,showError);

    }
  else{ alert("Geolocation is not supported by this browser.");}
  }

ShowPosition() using for Get latitude & longitude

function showPosition(position)
  {

    lati = position.coords.latitude;
    longi = position.coords.longitude;
}

showError() using for show the error

 function showError(error)
  {
  switch(error.code) 
    {
    case error.PERMISSION_DENIED:
      alert("User denied the request for Geolocation.");
      break;
    case error.POSITION_UNAVAILABLE:
      alert("Location information is unavailable.");
      break;
    case error.TIMEOUT:
      alert("The request to get user location timed out.");
      break;
    case error.UNKNOWN_ERROR:
      alert("An unknown error occurred.");
      break;
    }
  }

Thanks..

Refer the link : https://developers.google.com/maps/documentation/javascript/examples/map-geolocation

 

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s