-
Nov 12th, 2021, 01:46 AM
#1
Thread Starter
Member
geolocation question
I am following the example of this code from w3schools. The code below works on their website. But when I put it on my own webserver, and open it on browser, the browser doesnt ask for permission and no result will show. But when I just put the html file on my desktop and open it, the browser asks for permission and the result will show. I dont know what is causing the problem in the web server.
Code:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<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;
}
</script>
</body>
</html>
-
Nov 12th, 2021, 05:28 AM
#2
Re: geolocation question
Originally Posted by UserBee
I am following the example of this code from w3schools. The code below works on their website. But when I put it on my own webserver, and open it on browser, the browser doesnt ask for permission and no result will show. But when I just put the html file on my desktop and open it, the browser asks for permission and the result will show. I dont know what is causing the problem in the web server.
Code:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<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;
}
</script>
</body>
</html>
Which browser are you using? Some browsers will not support geolocation over an http connection, they require https for security reasons.
-
Nov 12th, 2021, 05:44 AM
#3
Thread Starter
Member
Re: geolocation question
I am. using chrome and firefox now for testing
-
Nov 12th, 2021, 07:59 AM
#4
-
Nov 12th, 2021, 08:06 AM
#5
Thread Starter
Member
Re: geolocation question
how do you add geolocation permission in a manifest? havent done it before!
-
Nov 12th, 2021, 08:12 AM
#6
Re: geolocation question
Originally Posted by UserBee
how do you add geolocation permission in a manifest? havent done it before!
Never done that either, realistically the only way to ensure this works properly is to host it on a valid https connection. What are you using for the web server?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|