@@ -39,7 +39,6 @@ export default function Map({ tavernEvents, tavernPeople, selectedTavern }) {
39
39
url = "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"
40
40
/>
41
41
< TavernMarkers people = { tavernPeople } events = { tavernEvents } />
42
- < UserLocation />
43
42
< MapUpdater selectedTavern = { selectedTavern } />
44
43
</ MapContainer >
45
44
< Card className = "mt-8 p-3 flex flex-row justify-center items-center gap-5 flex-wrap" >
@@ -83,22 +82,6 @@ export default function Map({ tavernEvents, tavernPeople, selectedTavern }) {
83
82
)
84
83
}
85
84
86
- function UserLocation ( ) {
87
- const map = useMap ( )
88
-
89
- useEffect ( ( ) => {
90
- if ( navigator . geolocation ) {
91
- navigator . geolocation . getCurrentPosition ( ( loc ) => {
92
- if ( map !== null ) {
93
- map . setView ( [ loc . coords . latitude , loc . coords . longitude ] , 11 )
94
- }
95
- } )
96
- }
97
- } , [ map ] )
98
-
99
- return null
100
- }
101
-
102
85
function MapUpdater ( {
103
86
selectedTavern,
104
87
} : {
@@ -107,13 +90,21 @@ function MapUpdater({
107
90
const map = useMap ( )
108
91
109
92
useEffect ( ( ) => {
110
- if ( selectedTavern && selectedTavern . geocode && map ) {
93
+ if ( ! map ) return
94
+
95
+ if ( selectedTavern && selectedTavern . geocode ) {
111
96
const geocodeData = JSON . parse (
112
97
atob ( selectedTavern . geocode . slice ( 2 ) . trim ( ) ) ,
113
98
)
114
99
if ( geocodeData . o . status === 'OK' ) {
115
100
map . setView ( [ geocodeData . o . lat , geocodeData . o . lng ] , 11 )
116
101
}
102
+ } else if ( navigator . geolocation ) {
103
+ navigator . geolocation . getCurrentPosition ( ( loc ) => {
104
+ if ( map !== null ) {
105
+ map . setView ( [ loc . coords . latitude , loc . coords . longitude ] , 11 )
106
+ }
107
+ } )
117
108
}
118
109
} , [ selectedTavern , map ] )
119
110
0 commit comments