2012-05-15 34 views
0

我試圖添加到一個可變數組中,並且無法弄清楚。將不兼容的數據類型double的錯誤引發到id。問題是我如何轉換距離並將其存儲在我的數組中。轉換cllocationdistance中的數據的問題

for (int i = 0; i < _getAllLocations.count; i++) { 

uscInfo *entity = [_getAllLocations objectAtIndex:i]; 
NSNumber *numlat=[[NSNumber alloc] initWithDouble:[entity.Latitude doubleValue]]; 
NSNumber *numlon=[[NSNumber alloc] initWithDouble:[entity.Longitude doubleValue]]; 
NSLog(@"%d",[_getAllLocations count]); 
la=[numlat doubleValue]; 
lo=[numlon doubleValue]; 
CLLocation *currentLocation = [[CLLocationalloc]initWithLatitude:lalongitude:lo];////here put your destination point 

//NSLog(@"New Location:%@", newLocation); 
CLLocationDistance distance = [newLocation distanceFromLocation:currentLocation]; 
NSLog(@"%@ (%@) %4.0f km from current location",entity.EntityNo, entity.EntityName, distance); 
NSLog(@"%@",currentLocation); 

我想保存在我的數組「locationDistance」「距離」

感謝您的幫助,我還是新到iOS以及編程一般。

回答

1

(你真的應該包括不工作的代碼 - 在這種情況下,實際addObject:代碼)

,但我可以告訴你,問題是你有可能試圖將裸CLLocationDistance添加到陣列中,這不會起作用,因爲它不是一個對象。它的typedef'd爲double,因此您需要使用它來包裝它,例如[NSNumber numberWithDouble:distance]

+0

謝謝[NSNumber numberWithDouble:distance]是我所需要的 –