简体   繁体   中英

Manipulating Pins in MapKit

I'm trying to make an annotation for a map and I want to change the pin color and add a subtitle. Does anybody know how to achieve this? Here is what I have thus far:

CLLocationCoordinate2D policestation1;
policestation1.latitude = 48.858822;
policestation1.longitude = 2.307463;
Maps2VC *annotation2 = [[Maps2VC alloc] initWithCoordinate:policestation1 title:@"Police Station"];
[self.mapView addAnnotation:(id)annotation2];

Implement the mapView:viewForAnnotation: function of MKMapViewDelegate

Do something like this to use a custom image:

-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

    MKAnnotationView *annotationView = [[MKAnnotationView alloc ] initWithAnnotation:annotation reuseIdentifier:@"annotationView"];
    annotationView.image = [UIImage imageNamed:@"mapMarker.png"];

    return annView;

}

I don't think you can change the pin colour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM