[raw]
Click the button to get your coordinates:
[/raw]
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Try It</button>
<script>
var x=document.getElementById("demo");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
x.innerHTML="Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude + "<br>Map: <a href=http://maps.google.com/?q=" + position.coords.latitude + "," + position.coords.longitude + " target=_blank>http://maps.google.com/?q=" + position.coords.latitude + "," + position.coords.longitude + "</a>";
}
</script>
</body>
</html>
Source: http://www.w3schools.com/html/html5_geolocation.asp
Originally Posted on November 5, 2013
Last Updated on October 26, 2015
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.