react-native-maps: Android map not working correctly, markers loading and not loading

Summary

map load but dont display markers.

Reproducible sample code

https://github.com/edgarscr/minimal-error-expo

Steps to reproduce

npm -v 10.8.2

node -v v20.18.0

npm install

npx expo start --clear --go

Expected result

Always need show markers

Actual result

open app markers appear on map on first load but if u close and open again map load but dont display markers.

React Native Maps Version

1.18.0

What platforms are you seeing the problem on?

Android

React Native Version

0.76.3

What version of Expo are you using?

SDK 52

Device(s)

Any android

Additional information

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 21
  • Comments: 16

Commits related to this issue

Most upvoted comments

I’m facing this problem and I came up with a somewhat inelegant workaround. I’ve noticed that the MapView component doesn’t actually invoke the onMapReady callback when the markers are not loaded. So, using a state variable and useEffect, I check if the markers are not loaded and force the re-render of the map if that’s the case. You can take a look at this code for some more insight, hopefully it’s not too ugly

import { useEffect, useState } from 'react';
import { StyleSheet, View } from 'react-native';

import MapView, { Marker } from 'react-native-maps';

export const NoteItem = ({ note }) => {
	const [mapReady, setMapReady] = useState(false);
	const [forceReload, setForceReload] = useState(0);

	useEffect(() => {
		const timer = setTimeout(() => {
			if (!mapReady) {
				console.warn('Map was not ready within 1 second. Forcing re-render.');
				setForceReload((prev) => prev + 1);
			}
		}, 1000);

		return () => clearTimeout(timer);
	}, [mapReady]);

	return (
		<View>
			<MapView
				key={forceReload} // Re-render map when this change
				style={styles.map}
				initialRegion={{
					latitude: note.location.coords.latitude,
					longitude: note.location.coords.longitude,
					latitudeDelta: 0.01,
					longitudeDelta: 0.01,
				}}
				onMapReady={() => {
					setMapReady(true);
					console.log('Map loaded');
				}}
			>
				<Marker
					coordinate={{ latitude: note.location.coords.latitude, longitude: note.location.coords.longitude }}
					title={note.title}
					description={note.note}
				></Marker>
			</MapView>
		</View>
	);
};


const styles = StyleSheet.create({
	map: {
		width: 300,
		height: 200,
	},
	modalView: {
		margin: 20,
		backgroundColor: 'white',
		borderRadius: 20,
		padding: 35,
		alignItems: 'center',
		shadowColor: '#000',
		shadowOffset: {
			width: 0,
			height: 2,
		},
		shadowOpacity: 0.25,
		shadowRadius: 4,
		elevation: 5,
	},
});

This is good, but i was still having the issue of it not working sometimes on android, so update on this is

useEffect(() => {
    const timer = setTimeout(() => {
      if (!mapReady) {
        console.warn("Map was not ready within 2 second. Forcing re-render.");
        setForceReload((prev) => prev + 1);
      }
    }, 2000);

    return () => clearTimeout(timer);
  }, [mapReady, forceReload]);

I’m facing this problem and I came up with a somewhat inelegant workaround. I’ve noticed that the MapView component doesn’t actually invoke the onMapReady callback when the markers are not loaded. So, using a state variable and useEffect, I check if the markers are not loaded and force the re-render of the map if that’s the case. You can take a look at this code for some more insight, hopefully it’s not too ugly

import { useEffect, useState } from 'react';
import { StyleSheet, View } from 'react-native';

import MapView, { Marker } from 'react-native-maps';

export const NoteItem = ({ note }) => {
	const [mapReady, setMapReady] = useState(false);
	const [forceReload, setForceReload] = useState(0);

	useEffect(() => {
		const timer = setTimeout(() => {
			if (!mapReady) {
				console.warn('Map was not ready within 1 second. Forcing re-render.');
				setForceReload((prev) => prev + 1);
			}
		}, 1000);

		return () => clearTimeout(timer);
	}, [mapReady]);

	return (
		<View>
			<MapView
				key={forceReload} // Re-render map when this change
				style={styles.map}
				initialRegion={{
					latitude: note.location.coords.latitude,
					longitude: note.location.coords.longitude,
					latitudeDelta: 0.01,
					longitudeDelta: 0.01,
				}}
				onMapReady={() => {
					setMapReady(true);
					console.log('Map loaded');
				}}
			>
				<Marker
					coordinate={{ latitude: note.location.coords.latitude, longitude: note.location.coords.longitude }}
					title={note.title}
					description={note.note}
				></Marker>
			</MapView>
		</View>
	);
};


const styles = StyleSheet.create({
	map: {
		width: 300,
		height: 200,
	},
	modalView: {
		margin: 20,
		backgroundColor: 'white',
		borderRadius: 20,
		padding: 35,
		alignItems: 'center',
		shadowColor: '#000',
		shadowOffset: {
			width: 0,
			height: 2,
		},
		shadowOpacity: 0.25,
		shadowRadius: 4,
		elevation: 5,
	},
});

Facing same issue with new architecture, any fixes?

I am experiencing the same bug. I fetch the data for the region and the markers using a useEffekt hook, but sometimes the region and markers are just ignored and I see a world map without any data. The data is defintiely there, but not displayed. Even if I conditionally only render the map once the data is loaded it might not show the region and markers.

Experiencing the same. When that happens, neither onMapReady, nor onMapLoaded callback props fire. Scoped to RN 0.76, Expo v52, and the new Architecture

facing same issue

I am experiencing the same bug. I fetch the data for the region and the markers using a useEffekt hook, but sometimes the region and markers are just ignored and I see a world map without any data. The data is defintiely there, but not displayed. Even if I conditionally only render the map once the data is loaded it might not show the region and markers.

I’m facing the same issue. My solution was to set newArchEnabled to false in the gradle.properties file with "react-native": "0.76.5"

same issue here. Any fix??

Similar issue here, do we know if this is getting addressed?

If you are using Expo and run npx expo install --check, you will see in the logs that this package is not supported in React Native’s New Architecture. I believe this will also affect bare React Native apps using the New Architecture.

image

Temp Solution

You do not have to downgrade Expo or React Native to fix this. Simply set newArchEnabled to false in your app.json and rebuild your app:

  1. Update your app.json:
{
  "expo": {
    "android": {
      "newArchEnabled": false
    }
  }
}
  1. Rebuild your app by either:
    • Running expo prebuild again, or
    • Creating a new development build

This should resolve the marker issues you are experiencing.

Noticing the same issue with new architecture, on Android it seems like the child prop is not used to create actual child elements.

working (iOS) broken (android)
Screenshot from 2024-12-03 13-53-18 Screenshot from 2024-12-03 13-52-33

I found out about this error on the newArch. While i am able to zoom into the map using map ref and MapView onLayout prop, i can’t say thesame for MapMarker. As of now, it sometimes gets hidden when the page rerenders.

When i changed “newArchEnabled”: false, in my expo app.json, those issues did not occur.

I need the newArch for performance benefits of Flatlist and others, please fix.