[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *name = [NSArray arrayWithObjects:@"Marina Bay Sands", @"Sentosa", @"Singapore Polytechnic",nil];
NSArray *description = [NSArray arrayWithObjects:@"Got casino!!", @"Got Universal Studio Singapore!!", @"Best polytechnic in Singapore!",nil];
self.mapAnnotations = [[NSMutableArray alloc] initWithCapacity:3];
//Set coordinates for pin
CLLocationCoordinate2D location;
location.latitude = (double)1.2822463547298561;
location.longitude = (double) 103.85830879211426;
MapPin *mapPin = [[MapPin alloc] init];
[mapPin setCoordinate:location];
[mapPin setName: [name objectAtIndex:0]];
[mapPin setDescription:[description objectAtIndex:0]];
[self.mapAnnotations addObject:mapPin];
location.latitude = (double) 1.249404;
location.longitude = (double) 103.830321;
[mapPin setCoordinate:location];
[mapPin setName: [name objectAtIndex:1]];
[mapPin setDescription:[description objectAtIndex:1]];
[self.mapAnnotations addObject:mapPin];
location.latitude = (double) 1.309976;
location.longitude = (double) 103.775921;
[mapPin setCoordinate:location];
[mapPin setName: [name objectAtIndex:2]];
[mapPin setDescription:[description objectAtIndex:2]];
[self.mapAnnotations addObject:mapPin];
[self.mapView addAnnotations:self.mapAnnotations];
self.mapView.mapType = MKMapTypeStandard;
[self location];
mapView.showsUserLocation = YES;
嗨,而不是新的Xcode編程,這是我在viewDidLoad中的代碼。我試圖展示多個註釋,這只是爲了嘗試。但是從這些代碼中,我只能顯示1個註釋,它是我添加到mapAnnotations數組中的最後一個對象。多個註釋不顯示(Xcode mapview)
我能得到它的工作的唯一辦法是初始化mapPin1和mapPin2,而是採用mapPin所有,爲我要創建的其他兩個註解。但是這樣看來效率很低(如果我錯了,就糾正我),而且我有數百個數據要添加進來。不可能對它們進行硬編碼。
有人可以幫助我嗎?
謝謝=)
哦謝謝!它現在工作得很好! =) – mLjH
很高興我能幫到你。如果我的答案解決了您的問題,請將其標記爲這樣! –