Reputation: 65860
I have below mentioned JSFidle.But it's not working.Can you say why's that ?
Note: I want to run it on JSFiddle.It should show the Latitude and Longitude.
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;
}
Upvotes: 1
Views: 124
Reputation: 75707
Because you have your JavaScript set to run in the load
event (the second drop down on the left). The function getLocation
only exists within the scope of that load
handler, not in the global scope you're trying to call it from.
It works fine if you change it to 'No wrap - in <body>'
Upvotes: 1