From 8259d37022c41272d382b8922d04e95c99d58799 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Sun, 19 Mar 2023 13:08:29 -0400 Subject: [PATCH] Handle location errors more gracefully --- web-frontend/src/lib/Map.svelte | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web-frontend/src/lib/Map.svelte b/web-frontend/src/lib/Map.svelte index 3ba2205..17da6a3 100644 --- a/web-frontend/src/lib/Map.svelte +++ b/web-frontend/src/lib/Map.svelte @@ -13,8 +13,10 @@ const locationCheckedChanged = () => { if (locationChecked) { + console.log('Starting location'); map.locate({ setView: true, watch: true, enableHighAccuracy: true }); } else { + console.log('Stopping location'); map.stopLocate(); } }; @@ -23,7 +25,14 @@ if (browser) { const leaflet = await import('leaflet'); - map = leaflet.map(mapElement).setView([51.505, -0.09], 13); + map = leaflet.map(mapElement); + // TODO: Pick a better spot + map.setView([51.505, -0.09], 13); + map.on('locationerror', (e) => { + console.error('Error getting location', e); + locationChecked = false; + locationCheckedChanged(); + }); map.on('click', onMapClick); map.on('locationfound', (e) => { dispatch('locationfound', e);