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 in the map as the following picture
as I searched I found out that needed to use Custom Marker to accomplish the maker's design, then I created a Custom Marker component
import React, { Component } from "react";
import { View } from "react-native";
import {
Text,
Left,
Right,
Thumbnail,
} from "native-base";
const defaultEmployeeLogo = require("../../../assets/defualtEmployee.png");
class CustomMarker extends Component {
render() {
return (
<View style={{ flexDirection: 'row', width: 140, height: 60,
borderRadius: 70, backgroundColor: 'orange' }}>
<Left>
<Thumbnail source={defaultEmployeeLogo} />
</Left>
<Right>
<Text style={{
color: '#fef',
fontSize: 13,
paddingBottom: 2,
fontFamily: 'Roboto',
alignItems: 'center',
paddingRight: 10
}}>Mohammad</Text>
</Right></View >);
}
}
export default CustomMarker;
when I use CustomMarker.js class solely it works fine and it shows the image but when I use it as the marker custom view it doesn't show the image
I don't know why it can't render the image with Custom Marker in android. and here is my code where I'm using map, markers and custom marker class
return (
<View style={styles.map_container}>
<MapView
style={styles.map}
customMapStyle={customrMapStyle}
region={{
latitude: this.state.region.latitude,
longitude: this.state.region.longitude,
latitudeDelta: 0.4,
longitudeDelta: 0.41,
}} >
{
coordinationData.map(function (marker, i) {
let lat = marker.latLang.latitude;
let lang = marker.latLang.longitude;
<MapView.Marker
key={i}
coordinate={
{
latitude: lat,
longitude: lang,
latitudeDelta: 0.4,
longitudeDelta: 0.41
}
}
title={marker.title}
description={marker.description}
>
<CustomMarker />
</MapView.Marker>
})}
</MapView>
</View>
any kind of help would be appreciated.
Adding a marker in React Native MapsStart by importing Marker from react-native-maps . import { Marker } from "react-native-maps"; Next, render the <Marker /> component as a child of <MapView /> . Pass the coordinate for the marker in the coordinate prop.
Few alternatives for google maps in react native : Mapbox - https://www.npmjs.com/package/@mapbox/react-native-mapbox-gl. Yandex Map - https://www.npmjs.com/package/react-native-yandexmapkit.
Expo uses react-native-maps at react-native-maps/react-native-maps. No setup required for use within the Expo Go app. See below for instructions on how to configure for deployment as a standalone app on Android and iOS.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With