【问题标题】:How to set Marker location to users current location onInit, using react-native-maps and Marker Library如何使用 react-native-maps 和标记库将标记位置设置为用户当前位置 onInit
【发布时间】:2019-12-02 16:57:35
【问题描述】:

现在反应原生地图仅在点击 MapView 时获取标记位置

        <MapView scrollEnabled={true} style={styles.map} region={region} onPress={selectLocationHandler}>
            {markerCoordinates && <Marker title="picked Location" draggable={true}
        isPreselected={true} coordinate={markerCoordinates}></Marker>}
        </MapView>

我想在不点击地图视图的情况下标记我的当前位置

我有以下 MapView 和 Marker 代码

有人可以帮我吗?

【问题讨论】:

    标签: javascript reactjs react-native react-native-maps


    【解决方案1】:

    你可以这样做:

    componentDidMount() {
       this.watchID = navigator.geolocation.watchPosition(
           position => {
                const { latitude, longitude } = position.coords;
                this.marker._component.animateMarkerToCoordinate(
                    { latitude,longitude },
                    500);
       });
    }
    

    this._marker作为你的标记参考

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-16
      • 2018-12-20
      • 2021-10-27
      • 2014-03-25
      • 1970-01-01
      • 2018-05-13
      • 2018-07-13
      • 1970-01-01
      相关资源
      最近更新 更多