开发者

Changing the text which appear when clicking on an annotation

开发者 https://www.devze.com 2023-02-23 07:51 出处:网络
i use MapKit to locate user and i want to personnalize the text which appear when the user click on the annotation, the default text is current location

i use MapKit to locate user and i want to personnalize the text which appear when the user click on the annotation, the default text is current location

here is my code :

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
    MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentLoc"];

    // annotation color
    [annView setPinColor:MKPinAnnotationColorGreen];
    //annotation  Animation
    [annView setAnimatesDrop:YES];

    [a开发者_开发知识库nnView setCanShowCallout:YES];

    return annView;
}


You want to use MKAnnotationView rather than MKPinAnnotationView. MKAnnotationView has a property called annotation which has a property called title, so:

annview.annotation.title = @"title";

I haven't tested doing it this way exactly, the usual way to do it is to make a custom class that implements the MKAnnotation protocol and then add instances of that class to the map.

0

精彩评论

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