0

ネイティブアプリでGoogleマップを表示するためにreact-native-map air bnbを使用しています。 マップとマーカーが表示されますが、マーカーはドラッグできません。 これはreact-native-mapsドラッグdocsによると、私のスクリプトmarkerネイティブマップに反応することはできません

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

答えて

1

です:

これは、非値ベースの小道具です。これを追加すると、マーカーをドラッグ可能(再配置)することができます。

代わりの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> 

のようにそれを定義しなければならない。ここに私のプロジェクトの作業をドラッグ可能なマーカーバージョンの抜粋です。 Npmのインストールとリンクではなく、単にMapViewをインポートするためにExponent Componentsを使用するだけで気にすることはありません。

<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

関連する問題