I am trying to learn to use the geolocation using javascript. However, the script does not work as i thought. Below is my code :
<!doctype html>
<html>
<title> Testing Geolocation</title>
<head>
<script>
function displayLocation(){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var div = document.getElementById("myLocation");
div.innerHTML =" You are at Latitude "+latitude+" and longitude "+longitude);}
window.onload = getMyLocation;}
function getMyLocation{
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(displayLocation);}
else{
alert("Oops! Geolocation function not supported");}
</script>
</head>
<body>
<div id="myLocation">
Your location will go here.
</div>
</body>
</html>
Hi, after correcting the typo, the script is still not working. i.e. the latitude and longitude is not showing.