【发布时间】:2012-01-19 16:59:15
【问题描述】:
[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 数组中的最后一个对象。
我可以让它工作的唯一方法是初始化 mapPin1 和 mapPin2,而不是全部使用 mapPin我要创建的两个注释。但是这种方式似乎效率很低(如果我错了,请纠正我)而且,我有数百个数据要添加。不可能对它们进行硬编码。
有人可以帮我解决这个问题吗?
谢谢你=)
【问题讨论】:
标签: ios xcode ipad annotations android-mapview