Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Implement the <code>viewForAnnotation</code> delegate method for doing this.</p> <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation { static NSString *identifier = @"MyLocation"; if ([annotation isKindOfClass:[yourAnnotationLocation class]]) { MKAnnotationView *annotationView = (MKAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; if (annotationView == nil) { annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; annotationView.enabled = YES; annotationView.canShowCallout = YES; //if you need image you can set it like //annotationView.image = [UIImage imageNamed:@"yourImage.png"];//here we use a nice image instead of the default pins annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; } else { annotationView.annotation = annotation; } if ([annotation.title isEqualToString:@"Midhun"]) { annotationView.pinColor = MKPinAnnotationColorGreen; } else { annotationView.pinColor = MKPinAnnotationColorRed; } return annotationView; } return nil; } </code></pre> <p>For setting custom property to your annotation add a class which confirms to <code>MKAnnotation</code> protocol.</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;MapKit/MapKit.h&gt; @interface MyLocation : NSObject &lt;MKAnnotation&gt; { NSString *_name; NSString *_address; int _yourValue; CLLocationCoordinate2D _coordinate; } @property (copy) NSString *name; @property (copy) NSString *address; @property (assign) yourValue; @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; - (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate; @end </code></pre> <p>This is is a nice <a href="http://www.raywenderlich.com/2847/introduction-to-mapkit-on-ios-tutorial" rel="nofollow"><strong>tutorial</strong></a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload