设置React-Native MapView触摸事件处理程序

时间:2015-06-19 19:10:53

标签: react-native

Facebook的MapView是否仅用于显示注释(地图标记)?似乎没有办法为标记触摸事件添加事件处理程序。我是否必须使用http://react-components.com/component/react-native-mapbox-gl

之类的内容

2 个答案:

答案 0 :(得分:0)

答案 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)
 }