Alex
Alex

Reputation: 827

How to change icon on React Native Google Map?

This code help me get current position and draw marker.

    async componentDidMount() {
    navigator.geolocation.getCurrentPosition(
    ....

        this.setState({
          location,
          region: {
            latitude,
            longitude,
            latitudeDelta: 0.0143,
            longitudeDelta: 0.0134
          }
        });
      }, //ok
      () => {}, //error
      {
        timeout: 2000,
        enableHighAccuracy: true,
        maximumAge: 1000
      }
    );
  }

  handleLocationSelected = (data, { geometry }) => {
    const {
      location: { lat: latitude, lng: longitude }
    } = geometry;

    this.setState({
      destination: {
        latitude,
        longitude,
        title: data.structured_formatting.main_text
      }
    });
  };
.....

<Marker
                coordinate={destination}
                anchor={{ x: 0, y: 0 }}
                image="marker.png";
              >

How I can change icon on Google map marker ?

I tried add image:"maker.png"; but I must click or touch on it, the marker change.

UPDATE: I Updated my post.

Upvotes: 0

Views: 785

Answers (1)

MPN7
MPN7

Reputation: 1348

Try this:

<MapView.Marker
     image={require('./maker.png')}
     anchor={{ x: 0, y: 0 }}
     coordinate={destination}>
</MapView.Marker>,

Upvotes: 1

Related Questions