私は XCode の開発を始めたばかりで、助けが得られるかどうか疑問に思っていました。地図上に場所を表示しようとしています。マップが機能していて、基本的な注釈もあります。ただし、たとえば、ガソリンスタンドの注釈を緑色にしたいと思います。そして、おそらく赤いショッピングモール。チュートリアルを見つけましたが、すべて別の色に変わります。特定の注釈のみを赤く、その他を緑色にするにはどうすればよいですか? (分解しても構わないのであれば、私はまだ学ぼうとしています):)
ありがとう!
これが私のコードです。ViewController.h:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController <MKMapViewDelegate>
@property (nonatomic, strong) IBOutlet MKMapView *mapView;
@end
ViewController.m:
#import "ViewController.h"
#import "Annotation.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation (MKPinAnnotationView *)view {
view.pinColor = MKPinAnnotationColorGreen;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//---------- Grocery Stores--------------
//---------------Meijer Richmond,KY Annotation--------------
//Annotation
//Create a coordinate for use with the annotation
CLLocationCoordinate2D meijerRichmondLocation;
meijerRichmondLocation.latitude = 37.76486;
meijerRichmondLocation.longitude = -84.29691;
//Create annotation obj
Annotation *meijerAnnotation = [Annotation alloc];
meijerAnnotation.coordinate = meijerRichmondLocation;
meijerAnnotation.title = @"Meijer Richmond";
meijerAnnotation.subtitle = @" 2013 Lantern Ridge Dr.";
[self.mapView addAnnotation:meijerAnnotation];
//-------------------------------------------------------
//---------------Meijer Reynold Road Lexington, KY Annotation--------------
//Annotation
//Create a coordinate for use with the annotation
CLLocationCoordinate2D meijerLex1Location;
meijerLex1Location.latitude = 37.995744;
meijerLex1Location.longitude = -84.531546;
//Create annotation obj
Annotation *meijerLex1Annotation = [Annotation alloc];
meijerLex1Annotation.coordinate = meijerLex1Location;
meijerLex1Annotation.title = @"Meijer on Reynolds Road";
meijerLex1Annotation.subtitle = @"351 Meijer Way Suite 100";
[self.mapView addAnnotation:meijerLex1Annotation];
//----------------------------------------------------------------------
//---------------Meijer Lexington, KY Annotation-------------------------------
MKPointAnnotation *meijerLex2Annotation = [[MKPointAnnotation alloc] init];
meijerLex2Annotation.title = @"Meijer on Man-O-War";
meijerLex2Annotation.subtitle = @"2155 Paul Jones Way";
meijerLex2Annotation.coordinate = CLLocationCoordinate2DMake(38.0208932,-84.420606);
[self.mapView addAnnotation:meijerLex2Annotation];
//------------ Malls ----------------
//-------------------Mall Annotation---------------------
//Mall Annotation
//Create a coordinate for use with the annotation
CLLocationCoordinate2D fayetteMallLocation;
fayetteMallLocation.latitude = 37.9909;
fayetteMallLocation.longitude = -84.5269;
//Create annotation obj
Annotation *fayetteMallAnnotation = [Annotation alloc];
fayetteMallAnnotation.coordinate = fayetteMallLocation;
fayetteMallAnnotation.title = @"Fayette Mall";
fayetteMallAnnotation.subtitle = @"Lexington's Main Shopping Center.";
//-------------------------------------------------------
[self.mapView addAnnotation:fayetteMallAnnotation];
self.mapView.delegate = self;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end