Reputation: 2610
So I have the below code to receive my current longitude and latitude. It works once, but when I reload the page it doesn't work anymore when I press the button. Does anyone know what is causing this?
I'm using a node.js server.
<!DOCTYPE html>
<html>
<head>
<title>Get the Location</title>
<script type="text/javascript">
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(successfulPosition);
}
else
document.getElementById("result").innerHTML = "Your browser does not support HTML5 Geolocation";
}
function successfulPosition(location)
{
var lat = location.coords.latitude;
var long = location.coords.longitude;
document.getElementById("result").innerHTML = "Latitude: " + lat +
"<br />Longitude: " + long;
}
</script>
</head>
<body>
<div id="result"></div>
<button id="getPosition" onclick="getLocation();">Get Position</button>
</body>
</html>
Upvotes: 0
Views: 250
Reputation: 637
Are you using Chrome browser? There seems to be a known issue with Chrome v65. I updated to Chrome v66 and it seems to work consistently again. Although I still can't figure out why it's so slow (takes 5-10 seconds) whereas in safari it's pretty much instant.
EDIT:
I've logged an issue with the Chromium team regarding the sluggishness of the response. They've confirmed the issue and are looking into it. Let's hope for a resolution soon.
Upvotes: 1