HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Where am I</title>
<script src="myLoc.js"></script>
<link rel="stylesheet" href="myLoc.css">
</head>
<body>
<div id="location">
You location will go here.
</div>
</body>
</html>
JAVASCRIPT
window.onload = getMyLocation;
function getMyLocation()
{
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(displayLocation);
}
else{
alert("Oops, no geolocation support");
}
}
function displayLocation(position)
{
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var div = document.getElementById("location");
div.innerHTML = "You are at Latitude: "+latitude+ ", Longitude: "+longitude;
}