[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
很高兴我能帮到你。如果我的答案解决了您的问题,请将其标记为这样! –