I m using map in my application. How to create a custom annotation in iphone? plz giv开发者_如何学运维e the link to the source...
in viewForAnnotation function
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView=nil;
if(annotation!=mapView.userLocation)
{
static NSString *defaultPinID=@"com.invasivecode.pin";
pinView=(MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if(pinView==nil)
pinView=[[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinID]autorelease];
pinView.pinColor=MKPinAnnotationColorRed;
pinView.canShowCallout=YES;
// to add button to annotation
UIButton *infobutton=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
// add ibaction to the button added
[infobutton addTarget:self action:@selector(showdet:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView=infobutton;
pinView.animatesDrop=YES;
[defaultPinID release];
}
}
精彩评论