October 2013
Intermediate to advanced
1053 pages
28h 7m
English
Instead of the default iOS SDK pins, you would like to display your own images as pins on a map view.
Load an arbitrary image into an instance of the UIImage class and assign it to the image property of the MKAnnotationView instance that you return to
your map view as a pin:
-(MKAnnotationView*)mapView:(MKMapView*)mapViewviewForAnnotation:(id<MKAnnotation>)annotation{MKAnnotationView*result=nil;if([annotationisKindOfClass:[MyAnnotationclass]]==NO){returnresult;}if([mapViewisEqual:self.myMapView]==NO){/* We want to process this event only for the Map Viewthat we have created previously */returnresult;}/* First typecast the annotation for which the Map View hasfired this delegate message */MyAnnotation*senderAnnotation=(MyAnnotation*)annotation;/* Using the class method we have defined in our customannotation class, we will attempt to get a reusableidentifier for the pin we are about to create */NSString*pinReusableIdentifier=[MyAnnotationreusableIdentifierforPinColor:senderAnnotation.pinColor];/* Using the identifier we retrieved above, we willattempt to reuse a pin in the sender Map View */MKPinAnnotationView*annotationView=(MKPinAnnotationView*)[mapViewdequeueReusableAnnotationViewWithIdentifier:pinReusableIdentifier];if(annotationView==nil){/* If we fail to reuse a pin, then we will create one */annotationView=[[MKPinAnnotationViewalloc]initWithAnnotation ...
Read now
Unlock full access