Facebook的MapView是否仅用于显示注释(地图标记)?似乎没有办法为标记触摸事件添加事件处理程序。我是否必须使用http://react-components.com/component/react-native-mapbox-gl
之类的内容答案 0 :(得分:0)
你试过onAnnotationPress吗?
https://facebook.github.io/react-native/docs/mapview.html#content
答案 1 :(得分:0)
听到我的代码工作正常
constructor(props) {
super(props);
this.state = {
region : {latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,},
annotations : [],
};
for (var i = 0; i < this.props.list.length; i++) {
this.state.annotations[i] = {latitude:parseFloat(this.props.list[i].latitude),
longitude: parseFloat(this.props.list[i].longitude),
animateDrop: true,
/*title: this.props.list[i].name,
subtitle: this.props.list[i].address,*/
image : require('../images/icons/pharmacy-map-normal.png'),
id : i.toString()}
};
}
render() {
return (
<View>
<MapView
style={styles.map}
showsUserLocation={true}
region={this.state.region}
onAnnotationPress={this.onAnnotationPress}
annotations={this.state.annotations}>
</MapView>
</View>
);
}
onAnnotationPress =(annotation) =>{
alert(annotation.id)
}