React Native Maps: Markers image doesn't show using Custom Marker in react-native-maps
Use SVG
for this https://github.com/react-native-community/react-native-svg
<Marker
coordinate={{
longitude: lang,
latitude: lat,
}}
>
<View style={{
flexDirection: 'row', width: 100, height: 30,
backgroundColor: 'orange'
}}>
<Svg
width={40} height={30}>
<Image
href={url}
width={40}
height={30}
/>
</Svg>
<View
style={{
flexDirection: 'column'
}}
>
<Text
style={{
marginLeft: 2,
fontSize: 9,
color: '#ffffff',
fontWeight: 'bold',
textDecorationLine: 'underline'
}}
>{marker.title}</Text>
<Text
style={{
marginLeft: 2,
fontSize: 9,
color: '#ffffff',
fontWeight: 'bold',
textDecorationLine: 'underline'
}}
>{marker.description}</Text>
</View>
</View>
</Marker>
My problem was solved right now.
I hope your problem will be solved.
This is my clean code:
import React, {Component} from 'react';
import {ImageBackground, Text} from 'react-native';
import {Marker} from 'react-native-maps';
export default class CustomMarker extends Component {
state = {
initialRender: true
}
render() {
return (
<Marker
//...
>
<ImageBackground
source={require('../assets/cluster3_mobile.png')}>
// *** These lines are very important ***
onLoad={() => this.forceUpdate()}
onLayout={() => this.setState({initialRender: false})}
key={`${this.state.initialRender}`}
>
// **** This line is very very important ****
<Text style={{width: 0, height: 0}}>{Math.random()}</Text>
</ImageBackground>
</Marker>
);
}
}
I had the same problem.
When you first load an application, the image does not show, but for later loading, this problem is resolved and show image.
Just enough after the image is loaded call this.forceUpdate()
const defaultEmployeeLogo = require("../../../assets/defualtEmployee.png");
<Image source={defaultEmployeeLogo} onLoad={() => this.forceUpdate()}>
<Text style={{width:0, height:0}}>{Math.random()}</Text>
</Image>
You can track this:
https://github.com/react-community/react-native-maps/issues/924