Enable location in browser and get current latitude and longitude



Now here the browser provides support for doing this Geolocation features.
I.E 9, Firefox, Chrome, Safari, and Opera support Geolocation.

<button onclick="EnableLocationGetLatLong()">Enable Location</button>
<p id="ShowLatLong"></p>
 
Add the above HTML  tag in your HTML page.
<script>
var x = document.getElementById("ShowLatLong");
function EnableLocationGetLatLong() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(GetLatLong);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function GetLatLong(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
Add the above script tag in your script page.

0 Comment's

Comment Form

Submit Comment