LinkedIn Twitter RSS Reset

Get Latitude and Longitude Of User From Simple Javascript!

I am a big fan of Latitude and Longitude, as you all might know, I have other post related to Latitude and Longitude and Google Maps.
I came across one of the greatest feature of Mozilla Firefox 3.5, and that was to get the latitude and Longitude of user using simple Javascript. No API to use, No query to Google or anything. Here’s the code.

<script>
if (navigator.geolocation) {
 var watchID = navigator.geolocation.watchPosition(function(position) {
  do_something(position.coords.latitude, position.coords.longitude);
}
);
} else {
  alert("I'm sorry, but geolocation services are not supported by your browser.");
}

function do_something(lat,long){
alert(lat);
alert(long);
}
</script>

Remember this only works on Mozilla Firefox 3.5. I’ll later come up with using this method to plot user on Google Maps, So follow on !

2 Responses to “Get Latitude and Longitude Of User From Simple Javascript!”

  1. pradip
    August 2, 2011 at 9:27 am #

    this method is good but not woking on Safari browser.

  2. Filipo Grand
    January 23, 2012 at 4:04 pm #

    I tested in my iPhone 4 and runs so fine and well

    Thanks!

Leave a Comment