是否可以从 map View 中删除标记?如何从谷歌地图 View 中删除标记。我使用“react-native-maps”显示谷歌地图。
请帮忙。
最佳答案
为了能够删除或添加标记,您只需要这样做
//Note : my map markers is => this.props.markers
componentDidMount() {
this.renderMarkers(this.props.markers)
}
async renderMarkers(mapMarkers) {
let markers = [];
markers = mapMarkers.map(marker => (<Marker
key={marker.code}
coordinate={{latitude: marker.lat, longitude: marker.lng}}
onPress={{}}
/>)
);
this.setState({markers});
}
refreshMarkers() {
this.renderMarkers(this.props.markers).then(() => {
this.forceUpdate();
});
}
render() {
return (
<MapView
ref={(ref) => this.mapView = ref}
style={styles.map}
region={this.props.coordinate}
>
{this.state.markers}
</MapView>
);
}
关于react-native - 从谷歌地图中删除标记 react 原生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44127679/