Here's a stripped-down version of a script that displays position information every 5 seconds:
<script>
var showPositionError = function(error) {
document.getElementById("message").innerHTML = "Error: " + error.message
}
var showPosition = function(position) {
console.log(Date(), position.coords.latitude)
}
var loop = function() {
navigator.geolocation.getCurrentPosition(showPosition, showPositionError)
}
setInterval(loop, 5*1000)
</script>
It works, but the alert asking me to block or allow the query appears with every iteration.
If I delay answering for a while, it continues iterating, and when I finally do respond all pending queries happen at the same time (the line with 8 repetitions):
pos2.html:17 Mon Jul 18 2022 16:47:56 GMT-0400 (Eastern Daylight Time) 43.4470912
pos2.html:17 Mon Jul 18 2022 16:48:01 GMT-0400 (Eastern Daylight Time) 43.4470912
pos2.html:17 Mon Jul 18 2022 16:48:06 GMT-0400 (Eastern Daylight Time) 43.4470912
8 pos2.html:17 Mon Jul 18 2022 16:48:49 GMT-0400 (Eastern Daylight Time) 43.4470912
pos2.html:17 Mon Jul 18 2022 16:48:52 GMT-0400 (Eastern Daylight Time) 43.4470912
pos2.html:17 Mon Jul 18 2022 16:48:56 GMT-0400 (Eastern Daylight Time) 43.4470912
This is using Chrome on Ubuntu 20.04.
There's obviously something I'm not understanding about how these mechanisms work.
What do I need to do so that it will ask for permission only the first time?