E.D
E.D

Reputation: 891

react-native-map marker images source from a state

i have a state like this:

this.state = {
        width :  Dimensions.get('window').width,
        height :  Dimensions.get('window').height,
        initialPosition:  {
          latitiude: 48.866667,
          longitude: 2.333333,
          latitudeDelta:LATITUDE_DELTA,
          longitudeDelta: LONGITUDE_DELTA
        },
        markerIcons: {},
        markers: [],
    };

In markerIcon i have different .png like this:

enter image description here

An din markers i have another object where appears different information and categories of traders :

enter image description here

I define my Markers as this in my render:

  {Object.keys(this.state.markers).map((marker, key) => (
          <Marker
              key={key}
              coordinate={this.state.markers[marker].coordinate}
              title={this.state.markers[marker].title}
              description={this.state.markers[marker].address}
              image={......}
          />
        ))}   
          </MapView>
        </View>

I would like the source of my images to match the categories of my traders.
The names are the same in both objects but how do I do it in my marker?? How can can i set my image source of my marker ??

thanks for your help ;)

Upvotes: 0

Views: 1391

Answers (2)

Vijay Kumar Mahar
Vijay Kumar Mahar

Reputation: 59

You can use custom icon this way a busy cat

Upvotes: 3

Pritish Vaidya
Pritish Vaidya

Reputation: 22209

You can access the object of the marker icon like this

Assuming that your marker icon object is stored in MarkerIcon

this.state.markerIcons[this.state.markers[marker].category]

This will give you the object {icon: '', label: ''} for the same

Upvotes: 0

Related Questions