Compare commits

..

No commits in common. "e516f9fce54f8cedc7f4da0d076958ef4782304f" and "a3e6809e248cbe5a6546b61e2c7ca126b9a64b0d" have entirely different histories.

2 changed files with 38 additions and 47 deletions

View file

@ -2,52 +2,13 @@
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();
@ -58,7 +19,7 @@
minZoom: 12
});
map.setView([latitude, longitude], 13);
map.setView(parmaCoordinates, 13);
map.setMaxBounds(map.getBounds());
leaflet
@ -67,8 +28,6 @@
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
})
.addTo(map);
});
onDestroy(async () => {

View file

@ -6,10 +6,42 @@
let syncWorker: Worker | undefined = undefined;
let latitude;
let longitude;
let accuracy;
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);
export let data;
let divider;