CLLocationCoordinate2D

CLLocationCoordinate2D

我试图创建然后检索CLLocationCoordinate2D对象的数组,但是由于某种原因,该数组始终为空。

我有:

NSMutableArray *currentlyDisplayedTowers;
CLLocationCoordinate2D new_coordinate = { currentTowerLocation.latitude, currentTowerLocation.longitude };
[currentlyDisplayedTowers addObject:[NSData dataWithBytes:&new_coordinate length:sizeof(new_coordinate)] ];

我也尝试过添加数据:
[currentlyDisplayedTowers addObject:[NSValue value:&new_coordinate withObjCType:@encode(struct CLLocationCoordinate2D)] ];

无论哪种方式,[currentlyDisplayedTowers计数]始终返回零。任何想法可能出什么问题吗?

谢谢!

最佳答案

要停留在对象域中,可以创建CLLocation实例,并将其添加到可变数组中。

CLLocation *towerLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
[currentDisplayedTowers addObject:towerLocation];

要从CLLocationCoordinate返回CLLocation结构,请在对象上调用coordinate
CLLocationCoordinate2D coord = [[currentDisplayedTowers lastObject] coordinate];

10-08 11:36