diff --git a/frontend/src/lib/components/tabs/MapTab.svelte b/frontend/src/lib/components/tabs/MapTab.svelte index 13d018a..68778fb 100644 --- a/frontend/src/lib/components/tabs/MapTab.svelte +++ b/frontend/src/lib/components/tabs/MapTab.svelte @@ -8,6 +8,42 @@ let map; let layerGroup; + const loadWorker = async () => { + if (!("geolocation" in navigator)) { + /* geolocation is not available */ + return; + } + + const options = { + enableHighAccuracy: true, + timeout: 5000, + maximumAge: 0, + }; + + function success(pos) { + const crd = pos.coords; + + let string = ""; + + latitude = crd.latitude; + longitude = crd.longitude; + accuracy = crd.accuracy; + + string += "Your current position is:"; + string += `Latitude : ${crd.latitude}`; + string += `Longitude: ${crd.longitude}`; + string += `More or less ${crd.accuracy} meters.`; + } + + function error(err) { + console.warn(`ERROR(${err.code}): ${err.message}`); + } + + navigator.geolocation.watchPosition(success, error, options); + }; + + + onMount(async () => { leaflet = await import('leaflet'); layerGroup = leaflet.layerGroup(); @@ -28,6 +64,8 @@ '© OpenStreetMap contributors' }) .addTo(map); + + loadWorker(); }); onDestroy(async () => { diff --git a/frontend/src/routes/routes/[slug]/+page.svelte b/frontend/src/routes/routes/[slug]/+page.svelte index 93ba127..19719bc 100644 --- a/frontend/src/routes/routes/[slug]/+page.svelte +++ b/frontend/src/routes/routes/[slug]/+page.svelte @@ -6,42 +6,10 @@ let syncWorker: Worker | undefined = undefined; - const loadWorker = async () => { - if (!("geolocation" in navigator)) { - /* geolocation is not available */ - return; - } - // const watchID = navigator.geolocation.watchPosition((position) => { - // latitude = position.coords.latitude; - // longitude = position.coords.longitude; - // console.log({latitude, longitude}); - // }); - - const options = { - enableHighAccuracy: true, - timeout: 5000, - maximumAge: 0, - }; - - function success(pos) { - const crd = pos.coords; - - let string = ""; - string += "Your current position is:"; - string += `Latitude : ${crd.latitude}`; - string += `Longitude: ${crd.longitude}`; - string += `More or less ${crd.accuracy} meters.`; - alert(string) - } - - function error(err) { - console.warn(`ERROR(${err.code}): ${err.message}`); - } - - navigator.geolocation.getCurrentPosition(success, error, options); - }; - - onMount(loadWorker); + let latitude; + let longitude; + let accuracy; + export let data; let divider;