标记反应原生地图不能拖动

问题描述:

我使用react-native-map空气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> 

根据docs可拖动的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> 

只是可以肯定,你是否试过按住标记拖动它?这有点慢。

+0

谢谢,现在解决,而我长按标记 – cahyowhy