ClLocationCoordinate2D的NSMutableArray

Sin*_*ina 21 iphone ios4

我正在尝试创建然后检索CLLocationCoordinate2D对象的数组,但由于某种原因,该数组始终为空.

我有:

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

我也试过这个来添加数据:

[currentlyDisplayedTowers addObject:[NSValue value:&new_coordinate withObjCType:@encode(struct CLLocationCoordinate2D)] ];
Run Code Online (Sandbox Code Playgroud)

无论哪种方式,[currentDisplayedTowers count]总是返回零.什么想法可能会出错?

谢谢!

Anu*_*rag 49

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

CLLocation *towerLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
[currentDisplayedTowers addObject:towerLocation];
Run Code Online (Sandbox Code Playgroud)

要从中获取CLLocationCoordinate结构CLLocation,请调用coordinate该对象.

CLLocationCoordinate2D coord = [[currentDisplayedTowers lastObject] coordinate];
Run Code Online (Sandbox Code Playgroud)