Note that there are some explanatory texts on larger screens.

plurals
  1. POMapKit mapView:viewForAnnotation has no effect on pin color
    text
    copied!<p>I can't seem to change the pin color.</p> <p>I have my view controller extend <code>&lt;MKMapViewDelegate&gt;</code> and implement <code>mapView:viewForAnnotation</code> I'm close but must be missing something. any help would be appreciated.</p> <p><strong>MainViewController.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import &lt;MapKit/MapKit.h&gt; #import "StopAnnotation.h" #define METERS_PER_MILE 1609.344 @interface MainViewController : UIViewController &lt;MKMapViewDelegate&gt; { } @property (weak, nonatomic) IBOutlet MKMapView *mapView; @end </code></pre> <p><strong>MapViewController.m</strong></p> <pre><code>#import "MainViewController.h" @implementation MainViewController @synthesize mapView=_mapView; - (void)viewWillAppear:(BOOL)animated { CLLocationCoordinate2D zoomLocation; zoomLocation.latitude = 43.066667; zoomLocation.longitude = -89.4; MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, METERS_PER_MILE, METERS_PER_MILE); MKCoordinateRegion adjustRegion = [_mapView regionThatFits:viewRegion]; [_mapView setRegion:adjustRegion animated:YES]; [_mapView addAnnotation:[[StopAnnotation alloc] initWithCoordinate:zoomLocation]]; } - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id&lt;MKAnnotation&gt;)annotation { MKPinAnnotationView *pav = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil]; pav.pinColor = MKPinAnnotationColorPurple; return pav; } // the rest of the methods are default, i.e. viewDid* and shouldAutorotate*, etc... </code></pre> <p><strong>StopAnnotation.h</strong></p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;MapKit/MapKit.h&gt; @interface StopAnnotation : NSObject &lt;MKAnnotation&gt; { CLLocationCoordinate2D coordinate; NSString *title; NSString *subtitle; } - (id)initWithCoordinate:(CLLocationCoordinate2D)c; @end </code></pre> <p><strong>StopAnnotation.m</strong></p> <pre><code>#import "StopAnnotation.h" @implementation StopAnnotation @synthesize coordinate; - (NSString *)subtitle { return @"subtitle"; } - (NSString *)title { return @"title"; } - (id)initWithCoordinate:(CLLocationCoordinate2D)c { coordinate = c; NSLog(@"%f,%f", c.latitude, c.longitude); return self; } @end </code></pre> <p>I'm doing an exercise &amp; the code was mostly from <a href="http://www.raywenderlich.com/2847/introduction-to-mapkit-on-ios-tutorial" rel="nofollow">here</a></p> <p>Thanks!!</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