Javascript 标记反应本地映射可以';t阻力

Javascript 标记反应本地映射可以';t阻力,javascript,react-native-android,react-native-maps,react-native,Javascript,React Native Android,React Native Maps,React Native,我已经使用react native map air bnb在我的本机应用程序中渲染了一张谷歌地图。 地图和标记已显示,但标记无法拖动。 这是我的剧本 <View style={Style.mapContainer}> <GeoLocation onSetInitalPos={this.onSetInitialPosition} onSetLastPos={this.onSetLastPosition}/&

我已经使用react native map air bnb在我的本机应用程序中渲染了一张谷歌地图。 地图和标记已显示,但标记无法拖动。 这是我的剧本

<View style={Style.mapContainer}>
            <GeoLocation onSetInitalPos={this.onSetInitialPosition}
                         onSetLastPos={this.onSetLastPosition}/>
            <MapView style={Style.map} region={this.state.region} onRegionChange={this.onRegionChange}>
                <MapView.Marker draggable={this.state.draggable}
                                coordinate={this.state.marker.latlng}
                                title={this.state.marker.title}
                                description={this.state.marker.description}
                                onDrag={() => console.log('onDrag')}
                />
            </MapView>
            <AutoCompleteMap onSetNewPlace={this.setMarkerPosition}/>
        </View>

console.log('onDrag')}
/>
根据
react native maps
可拖动的

这是一个非基于值的道具。添加此选项可以拖动(重新定位)标记

您应该这样定义它,而不是
draggable={this.state.draggable}

<MapView style={Style.map} region={this.state.region} onRegionChange={this.onRegionChange}>
  <MapView.Marker
    draggable
    coordinate={this.state.marker.latlng}
    title={this.state.marker.title}
    description={this.state.marker.description}
    onDragEnd={this.onUserPinDragEnd.bind(this)} />
</MapView>

下面是我的项目的可拖动标记版本的一个片段。没什么特别的,只是使用Exponent组件导入MapView,而不是npm安装和链接

   <Components.MapView
      ref={(map) => this.map = map}
      style={{width: Metrics.screenWidth, height: mapHeight, zIndex: 0}}
      region={{
        latitude: this.state.location.coords.latitude,
        longitude: this.state.location.coords.longitude,
        latitudeDelta: 0.0100,
        longitudeDelta: 0.0100,
      }}
    >
      <Components.MapView.Marker
        key={'i29'}
        draggable
        onDragEnd={this.onUserPinDragEnd.bind(this)}
        title={'You are here'}
        coordinate={{
          latitude: this.state.userLocation.coords.latitude,
          longitude: this.state.userLocation.coords.longitude,
        }}
      />
   </Components.MapView>
this.map=map}
style={{width:Metrics.screenWidth,height:mapHeight,zIndex:0}
区域={{
纬度:this.state.location.coords.latitude,
经度:this.state.location.coords.longitude,
纬度德尔塔:0.0100,
纵向德尔塔:0.0100,
}}
>

为了确定,你有没有试过按住标记来拖动它?有点慢。

什么是onUserPinDragEnd.bind???@BraianMellor拖动结束时调用的自定义函数。请参阅文档。文档不完整。这就是我问你的原因。我在一篇博客中找到了解决方案:如何获得标记停止位置上的当前lat&lng?为了有条件地使标记可拖动,可以将其定义为
draggable={this.state.draggable}
,或者
draggable={true}
/
draggable={false}