2017-04-15 34 views
0

我嘗試這樣做:如何添加鏈接(url)以反應原生地圖標註?

<MapView.Marker id={marker.id} 
       coordinate={marker.coordinates} 
       title={marker.title}> 
       <MapView.Callout style={styles.callout} > 
     <Text style={styles.link} onPress={this.openUrl.bind(this)}> 
        {this.props.marker.link} 
     </Text> 
    </MapView.Callout> 
</MapView.Marker> 

不過的OpenURL功能不調用。

回答

0

文本不含onPress回調,從文本移動onPressMapView.Callout

<MapView.Callout 
     onPress={this.openUrl.bind(this)} 
     style={styles.callout} 
     > 
      <Text style={styles.link}> 
       {this.props.marker.link} 
      </Text> 
</MapView.Callout> 

更新: 對於有多個鏈接,您可以使用自定義標註。從標註刪除onPress和點擊的孩子加入到標註:

 <MapView.Callout 
     style={styles.callout} 
     > 
     <TouchableOpacity 
      onPress={()=>{this.openUrl(this.props.marker.link1)}} 
     > 
      <Text style={styles.link}> 
      {this.props.marker.link1} 
      </Text> 
     </TouchableOpacity> 
     <TouchableOpacity 
      onPress={()=>{this.openUrl(this.props.marker.link2)}} 
     > 
      <Text style={styles.link}> 
      {this.props.marker.link2} 
      </Text> 
     </TouchableOpacity> 
     </MapView.Callout> 
+0

但在這種情況下,我不能在標註 –

+0

多個鏈接,添加多個可點擊的鏈接標註,你應該使用onPress在標註兒童中(見更新的答案)。 –