2015-06-19 68 views

回答

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