私は Xcode を初めて使用し、基本的には、MKMapView
各ピンに個別の色を追加したいと考えています。現在、ピンに注釈を付けています。
LocationAnnotation.h:
@interface LocationAnnotation : NSObject <MKAnnotation>
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end
LocationAnnotation.m:
#import "LocationAnnotation.h"
@implementation LocationAnnotation
@synthesize coordinate, title, subtitle;
@end
私の各座標は、MainMapViewController.h で次のようになります。
#define TheKingBill_LATITUDE 50.431379
#define TheKingBill_LONGITUDE -3.685495
//Annotation
NSMutableArray * locations = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location;
LocationAnnotation * myAnn;
//The King Bill Annotation
myAnn = [[LocationAnnotation alloc] init];
location.latitude = TheKingBill_LATITUDE;
location.longitude = TheKingBill_LONGITUDE;
myAnn.coordinate = location;
myAnn.title = @"The King Bill";
myAnn.subtitle = @"Another Pub In Town";
[locations addObject:myAnn];
//The Seven Stars Annotations
myAnn = [[LocationAnnotation alloc] init];
location.latitude = TheSevenStars_LATITUDE;
location.longitude = TheSevenStars_LONGITUDE;
myAnn.coordinate = location;
myAnn.title = @"The Royal Seven Stars Hotel";
myAnn.subtitle = @"Hotel In Town";
[locations addObject:myAnn];
[self.MainMapView addAnnotations:locations];
各ピンの色を変えるために何を追加する必要があるかについてのアイデアはありますか?
ありがとう!
さて、この LocationAnnotation ファイルにリンクする他のマップに問題があります。これにもカラーピンを追加したいです。新しいコードが以前の mapviewcontroller と同じであれば理想的です。これがコードです...
LocationAnnotation.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface LocationAnnotation : NSObject <MKAnnotation>
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property int idNumber;
- (id)initWithTitle:(NSString *)ttl andSubtitle:(NSString *)subttl andCoordinate:(CLLocationCoordinate2D)c2d andID:(int)idN;
@end
LocationAnnotation.m
#import "LocationAnnotation.h"
@implementation LocationAnnotation
@synthesize coordinate, title, subtitle, idNumber;
- (id)initWithTitle:(NSString *)ttl andSubtitle:(NSString *)subttl andCoordinate:(CLLocationCoordinate2D)c2d andID:(int)idN
{
self = [super init];
if (self)
{
self.title = ttl;
self.coordinate = c2d;
self.subtitle = subttl;
self.idNumber = idN;
}
return self;
}
@end
MapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapViewController : UIViewController
@property (weak, nonatomic) IBOutlet MKMapView *ClientMapView;
@end
MapViewController.m
#import "MapViewController.h"
#import "LocationAnnotation.h"
@interface MapViewController ()
@end
//The Dartmouth Inn Coordinates
#define DARTMOUTH_INN_LATITUDE 50.430036;
#define DARTMOUTH_INN_LONGITUDE -3.683873;
//Span
#define THE_SPAN 0.004f;
@implementation MapViewController
@synthesize ClientMapView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//Create the region
MKCoordinateRegion myRegion;
//Centre
CLLocationCoordinate2D centre;
centre.latitude = DARTMOUTH_INN_LATITUDE;
centre.longitude = DARTMOUTH_INN_LONGITUDE;
//Span
MKCoordinateSpan span;
span.latitudeDelta = THE_SPAN;
span.longitudeDelta = THE_SPAN;
myRegion.center = centre;
myRegion.span = span;
//Set The Map View
[ClientMapView setRegion:myRegion animated:YES];
//Annotation
//1. Create A Coordinate for use with annotation
CLLocationCoordinate2D dartLocation;
dartLocation.latitude = DARTMOUTH_INN_LATITUDE;
dartLocation.longitude = DARTMOUTH_INN_LONGITUDE;
LocationAnnotation * myAnnotation = [LocationAnnotation alloc];
myAnnotation.coordinate = dartLocation;
myAnnotation.title = @"The Dartmouth Inn";
[self.ClientMapView addAnnotation:myAnnotation];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end