我正在尝试使标记在本机反应中可点击。例如,对于一家特定的餐厅,我想显示标记,当用户点击它时,显示餐厅的名称(现在可以使用),当用户点击餐厅的名称时,它会直接进入他们的网站。只是为了它:
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
}}
]};
}
Run Code Online (Sandbox Code Playgroud)
稍后显示地图:
<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'}
/> )
)}
Run Code Online (Sandbox Code Playgroud)
假设我希望用户在点击 Royal Bengal 时转到 google.com,我应该怎么做?使用 onPress 和其他人查看文档并没有多大帮助。