location attempt to fix

This commit is contained in:
Ota Prokopec 2023-04-06 16:51:24 +02:00
parent c39f68cef5
commit 6d4c44b262
2 changed files with 17 additions and 5 deletions

View File

@ -54,7 +54,13 @@
<Map on:ready={() => setTimeout(() => userCenter(), 100)} {center} bind:mapComponent class={className} on:move> <Map on:ready={() => setTimeout(() => userCenter(), 100)} {center} bind:mapComponent class={className} on:move>
<slot /> <slot />
<GeolocateControl <GeolocateControl
options={{ trackUserLocation: true }} options={{
trackUserLocation: true,
showUserHeading: true,
positionOptions: {
enableHighAccuracy: true,
},
}}
on:trackuserlocationstart={() => {}} on:trackuserlocationstart={() => {}}
on:geolocate={(e) => { on:geolocate={(e) => {
// @ts-ignore // @ts-ignore

View File

@ -7,13 +7,13 @@
import { getExperiencesAsStore } from '$lib/utils/database/experience' import { getExperiencesAsStore } from '$lib/utils/database/experience'
import { onMount } from 'svelte' import { onMount } from 'svelte'
let user: { lat: number; lng: number } = { lat: 0, lng: 0 } let userLocation: { lat: number; lng: number } = { lat: 0, lng: 0 }
let granted = false let granted = false
const lastGame = localStorage.getItem('lastGame') const lastGame = localStorage.getItem('lastGame')
const handleLocationGranted = (position: GeolocationPosition) => { const handleLocationGranted = (position: GeolocationPosition) => {
user = { lat: position.coords.latitude, lng: position.coords.longitude } userLocation = { lat: position.coords.latitude, lng: position.coords.longitude }
granted = true granted = true
} }
@ -25,9 +25,15 @@
<NavigationBarLayout> <NavigationBarLayout>
{#if granted} {#if granted}
<!-- Conditionally center on current location if granted is true. --> <!-- Conditionally center on current location if granted is true. -->
<Erantmap class="w-full h-full" center={{ lng: user.lng, lat: user.lat }} bind:user> <Erantmap class="w-full h-full" center={{ lng: userLocation.lng, lat: userLocation.lat }}>
{#each $experiences as experience} {#each $experiences as experience}
<Marker popup={experience.ExpName} on:click={() => navigate(`/${experience.ExpURL}`)} lat={experience.ExpLocation[0]} lng={experience.ExpLocation[1]} {user} /> <Marker
popup={experience.ExpName}
on:click={() => navigate(`/${experience.ExpURL}`)}
lat={experience.ExpLocation[0]}
lng={experience.ExpLocation[1]}
{userLocation}
/>
{/each} {/each}
</Erantmap> </Erantmap>
{:else} {:else}