Compare commits
2 commits
a3e6809e24
...
e516f9fce5
Author | SHA1 | Date | |
---|---|---|---|
e516f9fce5 | |||
6a28949f41 |
2 changed files with 47 additions and 38 deletions
|
@ -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 @@
|
|||
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
})
|
||||
.addTo(map);
|
||||
|
||||
|
||||
});
|
||||
|
||||
onDestroy(async () => {
|
||||
|
|
|
@ -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});
|
||||
// });
|
||||
let latitude;
|
||||
let longitude;
|
||||
let accuracy;
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue