Anant kamat
Anant kamat

Reputation: 373

react native map polyline is not showing

This is my code.


<View style={styles.map}>
        <MapView
          style={styles.map}
          initialRegion={this.state.region}
          onRegionChangeComplete={this.onRegionChange}
        />
        {
          this.state.allow_set_location ?
            <View style={styles.markerFixed}>
              <Image style={styles.marker} source={marker} />
            </View> : null
        }

        <Polyline
          coordinates={this.state.route_data}
          strokeWidth={1}
          strokeColor="red"
          fillColor="rgba(255,0,0,0.5)"
        />
      </View>

i am not able to get the polyline. my route_data is array of objects, like [{latitude: data, longitude: data}.....]

Upvotes: 1

Views: 2526

Answers (1)

Isaac
Isaac

Reputation: 12874

Polyline should be wrapped by MapView component, instead of side by side.

       <View style={styles.map}>
        <MapView
          style={styles.map}
          initialRegion={this.state.region}
          onRegionChangeComplete={this.onRegionChange}
        >
          <Polyline
            coordinates={this.state.route_data}
            strokeWidth={1}
            strokeColor="red"
            fillColor="rgba(255,0,0,0.5)"
          />
       </MapView>
      </View>

Upvotes: 3

Related Questions