Tell user to refresh the page, if access to location has failed

at least in my local firefox on laptop, it would not prompt user again
until page was refreshed
This commit is contained in:
Lance Edgar 2024-06-08 19:35:03 -05:00
parent c2e6bfcfdd
commit 5d079e1208

View file

@ -11,6 +11,7 @@ export default {
return { return {
coordinates: null, coordinates: null,
loading: false, loading: false,
locationAccessBlocked: false,
} }
}, },
@ -22,13 +23,19 @@ export default {
useCurrentLocation() { useCurrentLocation() {
if (location.protocol == 'http:') { if (this.locationAccessBlocked) {
alert("Sorry, this only works for secure sites.") alert("You must refresh the page first, then try again.")
return
} }
navigator.geolocation.getCurrentPosition(loc => { navigator.geolocation.getCurrentPosition(loc => {
this.coordinates = `${loc.coords.latitude},${loc.coords.longitude}` this.coordinates = `${loc.coords.latitude},${loc.coords.longitude}`
this.loadCoordinates() this.loadCoordinates()
}, error => {
if (error.code == 1) { // PERMISSION_DENIED
this.locationAccessBlocked = true
}
alert(`error.code = ${error.code}\n\n${error.message}`)
}) })
}, },