开发者

How to create a custom annotation in map in iphone?

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];
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜