2012-07-24 63 views
1

我試圖找到一種直接的方式將MKCoordinateSpan放入數組中,而不會將其分解爲經緯度並將其存儲在NSArray中。不知道是否有這樣的方式。iOS:將MKCoordinateSpan對象放入數組中

+0

的可能重複的[添加和NSMutableArray的提取結構(http://stackoverflow.com/questions/5704722/add-and-extract-struct-from- nsmutablearray) – Vladimir 2012-07-24 14:40:21

回答

0

試試這個:

MKCoordinateSpan currentSpan; 
currentSpan = ...; // Set the span to somethinf 
NSValue *spanVal = [NSValue valueWithBytes:&currentSpan objCType:@encode(MKCoordinateSpan)]; 
... 
MKCoordinateSpan currentSpanBack; 
[spanVal getValue:&currentSpanBack]; 
+0

我從來沒有嘗試過這個,但我見過的例子表明它可能工作。 – dasblinkenlight 2012-07-24 14:43:13

+0

是的,它確實有效。 – Jano 2012-07-24 14:56:24

1
MKCoordinateSpan span = MKCoordinateSpanMake(1.0, 1.0); 
NSData *data = [NSData dataWithBytes:&span length:sizeof(span)]; 

MKCoordinateSpan back; 
[data getBytes:&back length:sizeof(back)]; 

NSLog(@"%f",back.latitudeDelta); 
+0

幾乎與下面我猜的一樣? +1努力:) – Byte 2012-07-24 17:03:37