I've been looking around for quite a bit and I haven't really found a good answer for this. I'm trying to change the color of the pin in a few different locations (1 red, 1 purple..)
I have a separate annotation class pinPlaceMark.h #import #import
@interface PinPlaceMark : NSObject <MKAnnotation>
@property(nonatomic, readwrite) CLLocationCoordinate2D coordinate;
@property(nonatomic, strong) NSString *myTitle;
@property(nonatomic, strong) NSString *mySubTitle;
- (id) initWithCoordinate: (CLLocationCoordinate2D) coordinate;
@end
pinPlaceMark.m
#import "PinPlaceMark.h"
@implementation PinPlaceMark
- (id) initWithCoordinate:(CLLocationCoordinate2D)coordinate
{
self = [super init];
if (self)
{
self.coordinate = coordinate;
}
return self;
}
- (NSString *) subtitle
{
return self.mySubTitle;
}
- (NSString *) title
{
return self.myTitle;
}
@end
mapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import "PinPlaceMark.h"
@interface MapViewController : UIViewController <MKMapViewDelegate>
@property (nonatomic, strong) IBOutlet MKMapView *mapView;
mapViewController.m
- (void) addPinWithCoordinate: (CLLocationCoordinate2D) pinLocation
{
PinPlaceMark *placeMark = [[PinPlaceMark alloc] initWithCoordinate:pinLocation];
placeMark.myTitle = @"This is my title";
placeMark.mySubTitle = @"This is my subtitle";
[self.mapView addAnnotation:placeMark];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.delegate = self;
CLLocationCoordinate2D pinLocation1;
pinLocation1.latitude = 40.7101843;
pinLocation1.longitude = -74.0061474;
[self addPinWithCoordinate:pinLocation1];
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"id"];
pinView.pinColor = MKPinAnnotationColorPurple;
return pinView;
Just for one color. How do I go about changing the color in different locations Ive tried creating another instance of MKPinAnnotationView and returning it based on the coordinates, but its not working for me.
Thanks for any help you can provide.