react-native - 从谷歌地图中删除标记 react 原生

标签 react-native react-redux wiki

是否可以从 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/

相关文章:

react-native - 使用 Redux 存储更新 FlatList 的最佳方法

java - react-native run-android 构建错误 ':app:generateDebugBuildConfig'

javascript - 在 React 组件中输入文本

javascript - 调用 Redux 操作时 Prop 不会更新

javascript - 维基百科如何将关键词变成链接?

android - 从 native android 应用程序中删除系统菜单栏

react-native - 如何使用 async/await 通过使用函数从 AsyncStorage 中检索值以响应 native

reactjs - 为什么位置固定减少了 react 的宽度?

phpDocumentor 到 wiki?

在 Google 代码上托管图像