我只是 XCode 的初级开发人员,想知道是否可以得到一些帮助。我正在尝试在地图上显示位置。我也有地图工作和基本注释。但是,例如,我希望加油站的注释是绿色的。也许是红色的购物中心。我找到了一个教程,但它变成了不同的颜色。我将如何只将某些注释设为红色而将其他注释设为绿色?(如果您不介意将其分解,我仍在努力学习):)
谢谢!
这是我的代码。视图控制器.h:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController <MKMapViewDelegate>
@property (nonatomic, strong) IBOutlet MKMapView *mapView;
@end
视图控制器.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