prop/assets/js/locate_me_hook.js
Graham McIntire 5acaaa9fa1 Support source=gps in URL for dynamic GPS-based bookmarks
Bookmarking /path?source=gps&destination=K5TR&band=10000 will use
the viewer's device GPS to resolve the source location on load.
The LocateMe hook handles both button clicks and server-pushed
request_gps events. Once coords are resolved, the URL is updated
with actual lat,lon and calculation runs automatically.
2026-04-07 13:48:03 -05:00

32 lines
881 B
JavaScript

export const LocateMe = {
mounted() {
this.el.addEventListener("click", () => this.locate())
// Also respond to server-pushed request (for source=gps URLs)
this.handleEvent("request_gps", () => this.locate())
},
locate() {
if (!navigator.geolocation) {
alert("Geolocation is not supported by this browser")
return
}
this.el.classList.add("loading", "loading-spinner")
navigator.geolocation.getCurrentPosition(
(pos) => {
this.el.classList.remove("loading", "loading-spinner")
this.pushEvent("gps_location", {
lat: pos.coords.latitude,
lon: pos.coords.longitude
})
},
(err) => {
this.el.classList.remove("loading", "loading-spinner")
alert("Could not get location: " + err.message)
},
{ enableHighAccuracy: true, timeout: 10000 }
)
}
}