Compare commits

..

2 commits

Author SHA1 Message Date
e516f9fce5 Set static coordinates
All checks were successful
ci/woodpecker/push/build Pipeline was successful
2023-07-18 17:50:42 +02:00
6a28949f41 Move geolocation service 2023-07-18 17:47:35 +02:00
2 changed files with 47 additions and 38 deletions

View file

@ -2,13 +2,52 @@
import { onMount, onDestroy } from 'svelte';
import { fade, fly } from 'svelte/transition';
const parmaCoordinates = [44.8, 10.32];
let mapElement: string | HTMLElement;
let leaflet;
let map;
let layerGroup;
let latitude;
let longitude;
let accuracy;
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 () => {
await loadWorker();
leaflet = await import('leaflet');
layerGroup = leaflet.layerGroup();
@ -19,7 +58,7 @@
minZoom: 12
});
map.setView(parmaCoordinates, 13);
map.setView([latitude, longitude], 13);
map.setMaxBounds(map.getBounds());
leaflet
@ -28,6 +67,8 @@
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
})
.addTo(map);
});
onDestroy(async () => {

View file

@ -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;