Add location to statistics
This commit is contained in:
parent
35dd00499f
commit
13f7163dd7
19
src/lib/scripts/getLocation.ts
Normal file
19
src/lib/scripts/getLocation.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
export function getCurrentLocation() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (navigator.geolocation) {
|
||||||
|
navigator.geolocation.getCurrentPosition(
|
||||||
|
(position) => {
|
||||||
|
resolve({
|
||||||
|
latitude: position.coords.latitude,
|
||||||
|
longitude: position.coords.longitude,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
reject(new Error("Geolocation is not supported by this browser."));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
import Nav from "$lib/navigation/nav.svelte";
|
import Nav from "$lib/navigation/nav.svelte";
|
||||||
import { getApiUrl } from "$lib/scripts/upstream";
|
import { getApiUrl } from "$lib/scripts/upstream";
|
||||||
import { featureDetect } from "$lib/scripts/featureDetect";
|
import { featureDetect } from "$lib/scripts/featureDetect";
|
||||||
|
import { getCurrentLocation } from "$lib/scripts/getLocation";
|
||||||
const title = "Statistics";
|
const title = "Statistics";
|
||||||
|
|
||||||
async function getData() {
|
async function getData() {
|
||||||
@ -132,6 +133,17 @@
|
|||||||
Failed to detect browser features: {error.message}
|
Failed to detect browser features: {error.message}
|
||||||
{/await}
|
{/await}
|
||||||
|
|
||||||
|
<h3>Detected Location</h3>
|
||||||
|
{#await getCurrentLocation()}
|
||||||
|
Fetching Location...
|
||||||
|
{:then location}
|
||||||
|
{location.latitude}, {location.longitude}
|
||||||
|
<br />
|
||||||
|
<a target="_blank" rel="noopener noreferrer" href="https://www.openstreetmap.org/?mlat={location.latitude}&mlon={location.longitude}&zoom=12">View on Map</a>
|
||||||
|
{:catch error}
|
||||||
|
{error.message}
|
||||||
|
{/await}
|
||||||
|
|
||||||
<Nav />
|
<Nav />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
Loading…
Reference in New Issue
Block a user