2017-02-25 3 views
3

私はreact-native-mapsモジュールを使用しています。私はlat値とlong値を与えていて、MapView.Markerを使ってマーカーをクリックすると、マーカーとツールチップが表示されます。React-native:反応ネイティブマップのマーカーをクリックしないでツールチップを表示するには

しかし、マップが最初に読み込まれたときにマーカーをクリックしてツールチップを表示したいとします。

これはここに私のコードです:

<View style={styles.page}> 
     <MapView 
      ref="map" 
      style={styles.map} 
      region={this.state.region} 
      provider = {PROVIDER_DEFAULT} 
      zoomEnabled={true} 
      onRegionChange={this.onRegionChange.bind(this)} 
      pitchEnabled={true} 
      showsCompass={true} 
      liteMode={false} 
      showsBuildings={true} 
      showsTraffic={true} 
      showsIndoors={true} 
     > 
     <MapView.Marker 
     coordinate={this.state.marker.latlng} 
     title={this.state.marker.title} 
     description={this.state.marker.description} 
     image={require('./assets/pin.png')} 

    /> 

     </MapView> 
     </View> 

これを解決する方法をいずれかの助けをすることができます...

答えて

3

私が使用して私はMapViewのためのonLoad小道具の任意の並べ替えの任意のドキュメントを見つけることができませんでした代わりにsuggested hereとしてください。ツールチップを表示するにはマーカーにshowCallout methodを使用する必要があります。これを行うには、MapViewのonLayoutで使用できるマーカーの参照を追加します。

<View style={styles.page}> 
    <MapView 
     ref="map" 
     style={styles.map} 
     region={this.state.region} 
     provider = {PROVIDER_DEFAULT} 
     zoomEnabled={true} 
     onRegionChange={this.onRegionChange.bind(this)} 
     pitchEnabled={true} 
     showsCompass={true} 
     liteMode={false} 
     showsBuildings={true} 
     showsTraffic={true} 
     showsIndoors={true} 
     onLayout={() => { this.mark.showCallout(); }} 
    > 
     <MapView.Marker 
      ref={ref => { this.mark = ref; }} 
      coordinate={this.state.marker.latlng} 
      title={this.state.marker.title} 
      description={this.state.marker.description} 
      image={require('./assets/pin.png')} 
     /> 
    </MapView> 
</View> 
+0

こんにちは、あなたの応答のおかげで、私はあなたが修正されたコードが使用されているが、私は小さなエラーがあります。どのように私はonLayout()関数を書くことができますあなたは私に助言を与えることができます – Lavaraju

+0

@ Lavaraju何を取得しているエラーは何ですか?私が投稿する前にそれをテストして以来、サンプルコードはそのまま動作するはずです。 –

+0

エラーがレイアウト()関数を見つけることができませんでした – Lavaraju

1

カスタムコールアウトを使用することができます。ここ https://github.com/airbnb/react-native-maps#custom-callouts

は一例です:

<MapView.Marker coordinate={marker.latlng}> 
    <MyCustomMarkerView {...marker} /> 
    <MapView.Callout> 
    <MyCustomCalloutView {...marker} /> 
    </MapView.Callout> 
</MapView.Marker> 

反応するネイティブ・マップのためのカスタムコールアウトのための例に従ってください: https://github.com/airbnb/react-native-maps/tree/master/example/examples

+0

私はあなたのコードを理解していません。 'MyCustomMarkerView'と' MyCustomCalloutView'はどうなっていますか? –

+0

Mr @AnkushRish私はあなたのコードを取得していません – Lavaraju

関連する問題