skip to Main Content

I am using react-native-maps (version 1.20.1) in my React Native project, and I am facing an issue where markers and the user location (blue dot) are not displaying consistently.

The first time I load the app (after clearing the Expo cache with npx expo start -c), everything works fine, but on subsequent reloads or when I navigate back to the map screen, the markers and user location disappear. Occasionally, they appear randomly but are not consistent.

At first i tried to debug using the logs

useEffect(() => {
  if (markers) {
    console.log("Markers loaded ", markers);
  }
}, [markers]);

in the terminal is said the Markers Loaded and with markers info but nothing was shown in the Map Page.

Then I thought the issue was with the AsyncStorage, so thought to clear it.

const clearStorage = async () => {
    try {
      await AsyncStorage.clear();
      console.log('AsyncStorage cleared!');
    } catch (error) {
      console.error('Failed to clear AsyncStorage:', error);
    }
  };

  // Clear AsyncStorage when the app loads
  useEffect(() => {
    clearStorage();
  }, []);

still did not work as expected.

2

Answers


  1. Try to make sure that the map is not being rendered twice. Add a constant key to your MapView Component to make sure there is only one instance of the map:

    <MapView
       key={"map-instance"}
       ...
    />
    
    Login or Signup to reply.
  2. I’m having the exact same issue. This is not an answer to your question, but I think the problem comes from the update to Expo 52 with the new architecture, which, as far as I understand it, is unavoidable if you wanna use Expo Go for testing. They’re working on it, but there isn’t a proper solution yet. You can browse through this issue on the react-native-maps github for more information:

    https://github.com/react-native-maps/react-native-maps/issues/5206

    If you’ve found something that works in the meantime, I’d love to hear it

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search