react-native-maps: Markers with custom images are rendered with the wrong size in production

When I render markers with custom images, I noticed that when __DEV__ is false, the image rendered has the same height and width as the file itself. When it’s true, it’s displayed with the proper height and width that I provide.

This happens on both iOS and Android.

Here’s a sample of my code :

            return (
                <MapView.Marker
                  key={`marker-${index}`}
                  coordinate={{ latitude: Number(latitude), longitude: Number(longitude) }}
                  onPress={options.onPress ? () => options.onPress(marker) : false}
                  image={icons[marker.type] || icons.default}
                  style={styles.marker}
                  identifier={marker._id}
                />
            );
export default StyleSheet.create({
    marker: {
        width: 60,
        height: 75
    }
});

And screenshots :

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17

Most upvoted comments

Now, for Android only works with Marker.Animated:

      <Marker.Animated
                identifier={`VagaMarker:${vaga.id}`}
                key={vaga.id}
                coordinate={new AnimatedRegion({
                    latitude: coord[0],
                    longitude: coord[1],
                })}
            >
                <Image
                    source={imageSource}
                    style={{ height: 50, width: 50 }}
                    resizeMode="contain"
                />
            </Marker.Animated>

But now work with normal Marker:

      <Marker
                identifier={`VagaMarker:${vaga.id}`}
                key={vaga.id}
                coordinate={{
                    latitude: coord[0],
                    longitude: coord[1],
                }}
            >
                <Image
                    source={imageSource}
                    style={{ height: 50, width: 50 }}
                    resizeMode="contain"
                />
            </Marker>

No errors, just marker does not appear.

I still think this is an issue as the behaviour in dev is different to the behaviour in release…

@robmoorman It looks like adding 2x, 3x, 4x images fixed it for us. Still weird that it didn’t happen in dev mode, though. Thanks anyway.

Correctly @mgtitimoli please read React Native’s docs for more information

@coreyphillips Putting an image inside MapView.Marker works fine but it’s not showing anything on an android emulator with a 26 version apk.

@danielbh I would suggest something similar to the following if adding 2x, 3x etc., doesn’t work for you:

<MapView.Marker
	coordinate={{ latitude, longitude }}
>
	<Image
		source={mySource}
		style={{ height: 22, width: 22 }}
	/>
</MapView.Marker>

I also noticed this, but thanks to @robmoorman I realised I didn’t specify @2x in my filename. D’oh. Thanks!

I can confirm this issue exists, in dev it uses the correct image sizes but in prod it gets the scaling wrong, it also ignores any height and width styles you add to the markers.