diff --git a/src/components/AddressSearch/index.tsx b/src/components/AddressSearch/index.tsx index 17a2f6212447..9bd6142b5604 100644 --- a/src/components/AddressSearch/index.tsx +++ b/src/components/AddressSearch/index.tsx @@ -14,6 +14,7 @@ import useNetwork from '@hooks/useNetwork'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import * as UserLocation from '@libs/actions/UserLocation'; import * as ApiUtils from '@libs/ApiUtils'; import getCurrentPosition from '@libs/getCurrentPosition'; import type {GeolocationErrorCodeType} from '@libs/getCurrentPosition/getCurrentPosition.types'; @@ -249,12 +250,17 @@ function AddressSearch( setIsFetchingCurrentLocation(false); setLocationErrorCode(null); + const {latitude, longitude} = successData.coords; + const location = { - lat: successData.coords.latitude, - lng: successData.coords.longitude, + lat: latitude, + lng: longitude, address: CONST.YOUR_LOCATION_TEXT, name: CONST.YOUR_LOCATION_TEXT, }; + + // Update the current user location + UserLocation.setUserLocation({longitude, latitude}); onPress?.(location); }, (errorData) => { diff --git a/src/components/MapView/MapView.tsx b/src/components/MapView/MapView.tsx index 48d820ae5103..1bd2337c56c2 100644 --- a/src/components/MapView/MapView.tsx +++ b/src/components/MapView/MapView.tsx @@ -25,7 +25,7 @@ import type {ComponentProps, MapViewOnyxProps} from './types'; import utils from './utils'; const MapView = forwardRef( - ({accessToken, style, mapPadding, userLocation: cachedUserLocation, styleURL, pitchEnabled, initialState, waypoints, directionCoordinates, onMapReady, interactive = true}, ref) => { + ({accessToken, style, mapPadding, userLocation, styleURL, pitchEnabled, initialState, waypoints, directionCoordinates, onMapReady, interactive = true}, ref) => { const navigation = useNavigation(); const {isOffline} = useNetwork(); const {translate} = useLocalize(); @@ -34,7 +34,7 @@ const MapView = forwardRef( const cameraRef = useRef(null); const [isIdle, setIsIdle] = useState(false); const initialLocation = useMemo(() => initialState && {longitude: initialState.location[0], latitude: initialState.location[1]}, [initialState]); - const [currentPosition, setCurrentPosition] = useState(cachedUserLocation ?? initialLocation); + const currentPosition = userLocation ?? initialLocation; const [userInteractedWithMap, setUserInteractedWithMap] = useState(false); const shouldInitializeCurrentPosition = useRef(true); @@ -50,7 +50,6 @@ const MapView = forwardRef( return; } UserLocation.clearUserLocation(); - setCurrentPosition(initialLocation); }, [initialLocation], ); @@ -74,7 +73,6 @@ const MapView = forwardRef( getCurrentPosition((params) => { const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude}; - setCurrentPosition(currentCoords); UserLocation.setUserLocation(currentCoords); }, setCurrentPositionToInitialState); }, [isOffline, shouldPanMapToCurrentPosition, setCurrentPositionToInitialState]), diff --git a/src/components/MapView/MapView.website.tsx b/src/components/MapView/MapView.website.tsx index 640469126874..bfa923fa2af4 100644 --- a/src/components/MapView/MapView.website.tsx +++ b/src/components/MapView/MapView.website.tsx @@ -39,7 +39,7 @@ const MapView = forwardRef( waypoints, mapPadding, accessToken, - userLocation: cachedUserLocation, + userLocation, directionCoordinates, initialState = {location: CONST.MAPBOX.DEFAULT_COORDINATE, zoom: CONST.MAPBOX.DEFAULT_ZOOM}, interactive = true, @@ -55,7 +55,7 @@ const MapView = forwardRef( const [mapRef, setMapRef] = useState(null); const initialLocation = useMemo(() => ({longitude: initialState.location[0], latitude: initialState.location[1]}), [initialState]); - const [currentPosition, setCurrentPosition] = useState(cachedUserLocation ?? initialLocation); + const currentPosition = userLocation ?? initialLocation; const [userInteractedWithMap, setUserInteractedWithMap] = useState(false); const [shouldResetBoundaries, setShouldResetBoundaries] = useState(false); const setRef = useCallback((newRef: MapRef | null) => setMapRef(newRef), []); @@ -73,7 +73,6 @@ const MapView = forwardRef( return; } UserLocation.clearUserLocation(); - setCurrentPosition(initialLocation); }, [initialLocation], ); @@ -97,7 +96,6 @@ const MapView = forwardRef( getCurrentPosition((params) => { const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude}; - setCurrentPosition(currentCoords); UserLocation.setUserLocation(currentCoords); }, setCurrentPositionToInitialState); }, [isOffline, shouldPanMapToCurrentPosition, setCurrentPositionToInitialState]),