diff --git a/src/components/MapView/MapView.tsx b/src/components/MapView/MapView.tsx index db3e076eacca..7b63836efa66 100644 --- a/src/components/MapView/MapView.tsx +++ b/src/components/MapView/MapView.tsx @@ -28,6 +28,7 @@ const MapView = forwardRef( const [isIdle, setIsIdle] = useState(false); const [currentPosition, setCurrentPosition] = useState(cachedUserLocation); const [userInteractedWithMap, setUserInteractedWithMap] = useState(false); + const hasStartedGettingCurrentPosition = useRef(false); useFocusEffect( useCallback(() => { @@ -35,6 +36,12 @@ const MapView = forwardRef( return; } + if (hasStartedGettingCurrentPosition.current) { + return; + } + + hasStartedGettingCurrentPosition.current = true; + getCurrentPosition( (params) => { const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude}; diff --git a/src/components/MapView/MapView.web.tsx b/src/components/MapView/MapView.web.tsx index 1880049b3542..d34b8f1ac4d9 100644 --- a/src/components/MapView/MapView.web.tsx +++ b/src/components/MapView/MapView.web.tsx @@ -5,7 +5,7 @@ import {useFocusEffect} from '@react-navigation/native'; import mapboxgl from 'mapbox-gl'; import 'mapbox-gl/dist/mapbox-gl.css'; -import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useState} from 'react'; +import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'; import Map, {MapRef, Marker} from 'react-map-gl'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; @@ -47,6 +47,7 @@ const MapView = forwardRef( const [currentPosition, setCurrentPosition] = useState(cachedUserLocation); const [userInteractedWithMap, setUserInteractedWithMap] = useState(false); const [shouldResetBoundaries, setShouldResetBoundaries] = useState(false); + const hasStartedGettingCurrentPosition = useRef(false); const setRef = useCallback((newRef: MapRef | null) => setMapRef(newRef), []); useFocusEffect( @@ -55,6 +56,12 @@ const MapView = forwardRef( return; } + if (hasStartedGettingCurrentPosition.current) { + return; + } + + hasStartedGettingCurrentPosition.current = true; + getCurrentPosition( (params) => { const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude};