Skip to content

Markers/Polyline disappear after navigating back to MapView screen #5750

@Ikthegreat

Description

@Ikthegreat

Summary

When navigating away from a screen containing a MapView (using React Navigation stack push) and then returning with pop, the Marker and Polyline overlays disappear. The map itself still renders, but the overlays are gone.

Reproducible sample code

import { useNavigation } from '@react-navigation/native';
import { Button, View } from 'react-native';
import MapView, { Marker, Polyline, PROVIDER_GOOGLE } from 'react-native-maps';

const MapScreen = () => {
  const navigation = useNavigation();

  return (
    <View style={{ flex: 1 }}>
      <MapView
        provider={PROVIDER_GOOGLE}
        initialRegion={{
          latitude: 37.78825,
          longitude: -122.4324,
          latitudeDelta: 0.005,
          longitudeDelta: 0.005,
        }}
        style={{ flex: 1 }}
      >
        <Marker
          image={require('../../assets/marker.png')}
          coordinate={{ latitude: 37.78825, longitude: -122.4324 }}
        />

        <Polyline
          coordinates={[
            { latitude: 37.788, longitude: -122.432 },
            { latitude: 37.786, longitude: -122.431 },
            { latitude: 37.787, longitude: -122.433 },
            { latitude: 37.785, longitude: -122.434 },
          ]}
          strokeWidth={5}
        />
      </MapView>

      <Button title="Go to Next" onPress={() => navigation.navigate('Next')} />
    </View>
  );
};

export default MapScreen;

Steps to reproduce

  1. Create a screen (MapViewScreen) with a MapView containing at least one Marker and a Polyline.
  2. From that screen, push another screen onto the navigation stack.
  3. Navigate back to the MapViewScreen using pop (or back navigation).
  4. Observe that the MapView is still present, but the overlays (Marker/Polyline) are missing.

Expected result

When navigating back to the MapViewScreen, all previously rendered state should still be visible and unchanged.

Actual result

React Native Maps Version

1.26.9

What platforms are you seeing the problem on?

Android

React Native Version

0.81.4

What version of Expo are you using?

Not using Expo

Device(s)

Samsung Galaxy Flip 3 (Android 15)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions