【发布时间】:2018-08-30 23:00:12
【问题描述】:
我正在根据标记数组状态更新多个标记位置。所以当我用 setState 更新它时,渲染函数照常触发并且 mapview 重新渲染。由于它有一个初始区域和区域道具,它会根据玩家位置状态自动关注玩家位置(我不想要这个,我只想要在初始加载时这样做。)
如何在不重新渲染地图视图的情况下更新标记位置?
render() {
return (
<MapView
initialRegion={this.state.playerLocation}
region={this.state.playerLocation}
style={ styles.map }>
{this.renderMarkers()}
</MapView>
);
}
renderMarkers = () => {
return(
this.state.markers.map(marker=>{
return(
<Marker coordinate = {{
latitude: marker.lat,
longitude: marker.long
}}
title={marker.id}/>
)
})
}
【问题讨论】:
标签: reactjs react-native react-native-maps