I\'m using react-native-maps
but I faced a problem that after a lot of googling without answer makes me ask it here.
I\'m trying to use Custom Marker for the marker
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>
Add your custom marker component inside <View>
e.g. <View> your marker custom view </View>
. Maybe it will resolve your issue.
This is another example
class PinMarker extends Component {
state = {
initialRender: true
}
render() {
return (
<MapView.Marker coordinate={coordinate}>
<Image
source={...}
onLayout={() => this.setState({ initialRender: false })}
key={`${this.state.initialRender}`}
/>
</MapView.Marker>
)
}
}
@Mahdi Bashirpour solution works for me. just upgrading above answer.
Other Images stop working if we import 'Image' from 'react-native-svg'
My solution is below.
import {Image} from 'react-native'; // for other images in our render method.
import { Image as Imagesvg } from 'react-native-svg';
<Marker
coordinate={marker.latlng}
title={marker.title}
>
<View style={{ height: 90, width: 90, backgroundColor: 'orange' }}>
<Svg width={90} height={90}}>
<Imagesvg href={marker_g} width={90} height={90} /> // Local Images
<Imagesvg href={{uri:url}} width={90} height={90} /> //Server images
</Svg>
</View>
</Marker>
Use 'Imagesvg' for marker image. It's working for me on android 7 and 8. React native version '0.55.3'