[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マップビュー)
私は仕事にそれを得ることができる唯一の方法は、私が作成したい他の二つの注釈のため、代わりにすべてのためマッピンを使用しての、mapPin1とmapPin2を初期化することでした。しかし、この方法では非常に非効率的で(私が間違っている場合は私を修正してください)、さらに、私は追加するデータが何百もあります。
誰かが私にこれを手伝ってもらえますか?
は、あなたが1 mapPin
を作成し、繰り返し同じオブジェクトを追加している=)
オハイオ州の下に使用しますありがとう!それは今完璧に正常に動作します! =) – mLjH
私は助けてくれると嬉しいです。私の答えがあなたの問題を解決したら、そのようにマークしてください! –