diff --git a/src/components/MapView/MapView.tsx b/src/components/MapView/MapView.tsx index 553be816cf3f..57eec0510114 100644 --- a/src/components/MapView/MapView.tsx +++ b/src/components/MapView/MapView.tsx @@ -157,7 +157,8 @@ const MapView = forwardRef( } }; const centerMap = useCallback(() => { - if (directionCoordinates && directionCoordinates.length > 1) { + const waypointCoordinates = waypoints?.map((waypoint) => waypoint.coordinate) ?? []; + if (waypointCoordinates.length > 1 || (directionCoordinates ?? []).length > 1) { const {southWest, northEast} = utils.getBounds(waypoints?.map((waypoint) => waypoint.coordinate) ?? [], directionCoordinates); cameraRef.current?.fitBounds(southWest, northEast, mapPadding, CONST.MAPBOX.ANIMATION_DURATION_ON_CENTER_ME); return; diff --git a/src/components/MapView/MapView.website.tsx b/src/components/MapView/MapView.website.tsx index c8f4e9bb38fc..618dd5b24cf5 100644 --- a/src/components/MapView/MapView.website.tsx +++ b/src/components/MapView/MapView.website.tsx @@ -194,7 +194,8 @@ const MapView = forwardRef( if (!mapRef) { return; } - if (directionCoordinates && directionCoordinates.length > 1) { + const waypointCoordinates = waypoints?.map((waypoint) => waypoint.coordinate) ?? []; + if (waypointCoordinates.length > 1 || (directionCoordinates ?? []).length > 1) { const {northEast, southWest} = utils.getBounds(waypoints?.map((waypoint) => waypoint.coordinate) ?? [], directionCoordinates); const map = mapRef?.getMap(); map?.fitBounds([southWest, northEast], {padding: mapPadding, animate: true, duration: CONST.MAPBOX.ANIMATION_DURATION_ON_CENTER_ME});