+ 11
Whats wrong with this? Please help me. I dont really understand how to do that
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p id="Position" onload="getLocation()">Position</p> </body> </html> <srcipt> var x=document. getElementById("Position"); function getLocation() { if (navigator.geolocation) { navigator.geolocation. getCurrentPosition(showPosition); } else { x.innerHTML="Geolocation is not supported by this browser."; } } </script>
6 Réponses
+ 16
owh ... now I understand why this does not work .... thanks @ESDETE, you are very kind to help answer my question .... sorry if I can not give you an upvote, because my account is still not verified
+ 14
Oh, my God. I was less conscientious with my work. thanks a lot @ESDETE ^_^....i will fix it
+ 12
and now, how does it work?
it doesn't work on my divice.....is there any less?
+ 1
Hey Bryan,
- start tag "<srcipt>" instead of "<script>" :)
- the onload-event doesn't work with paragraph-elements.
- no function for "showPosition"
esdete
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body onload="getLocation()">
<p id="Position">Position</p>
<script>
var x=document.getElementById("Position");
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;
}
</script>
</body>
</html>
+ 1
Oh okay, it doesn't work on unsecured HTTP:
"As of Chrome 50, the Geolocation API will only work on secure contexts such as HTTPS. If your site is hosted on an non-secure origin (such as HTTP) the requests to get the users location will no longer function."
0
Hello