标记反应本机地图无法拖动



i've使用React-Native-Map Air BNB在我的本机应用中渲染Google地图。显示了地图和标记,但标记不会拖动。这是我的脚本

<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>

根据 react-native-maps draggable 的文档:

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

而不是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>

这是我项目的可拖动标记版本的片段。没什么好看的,只需使用指数组件导入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>

可以肯定的是,您是否尝试过按下标记来拖动它?有点慢。

最新更新