React native 可单击地图视图标记
我正在尝试使一个标记在react native中可点击。例如,对于一家特定的餐馆,我想显示标记,当用户点击它时,餐馆的名称(现在可以使用),当用户点击餐馆的名称时,它直接进入他们的网站。 只是为了它:React native 可单击地图视图标记,react-native,android-mapview,marker,React Native,Android Mapview,Marker,我正在尝试使一个标记在react native中可点击。例如,对于一家特定的餐馆,我想显示标记,当用户点击它时,餐馆的名称(现在可以使用),当用户点击餐馆的名称时,它直接进入他们的网站。 只是为了它: constructor(props){ super(props); this.state = { name: "", email: "", region: { // luxembourg region latitu
constructor(props){
super(props);
this.state = {
name: "",
email: "",
region: {
// luxembourg region
latitude: 49.6116,
longitude: 6.1319,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
},
markers: [{
title: 'Royal Bengal',
coordinates: {
latitude: 49.606259,
longitude: 6.105683
}}
]};
}
稍后显示地图:
<MapView
style={styles.map}
region={this.state.region}
showUserLocation = {true}
>
{this.state.markers.map((marker, index) => (
<MapView.Marker
key = {index}
coordinate = {marker.coordinates}
title = {marker.title}
// Icon =
// pinColor = {'#474744'}
/> )
)}
{this.state.markers.map((marker,index)=>(
)
)}
假设我想让用户在点击Royal Bengal时访问google.com,我该怎么做?与onPress和其他人一起查看文档并不是很有帮助。Linking.openURL('your-url')}
<MapView.Marker
key = {index}
onPress={() => Linking.openURL('your-url')}
coordinate = {marker.coordinates}
title = {marker.title}
/>
坐标={marker.coordinates}
title={marker.title}
/>
根据,onPress事件是使标记可点击的原因。
要在设备的默认浏览器中打开链接,请按照