在NSMutableArray Xcode中存储纬度和经度

时间:2012-08-14 10:54:18

标签: iphone objective-c ios xcode ipad

如何在NSMutableArray

中存储多个点(纬度和经度)

4 个答案:

答案 0 :(得分:6)

你有几个选择:

我推荐后者,因为您可能会发现以后需要CLLocation的额外功能。

答案 1 :(得分:1)

//NSMutable array to store values
NSMutableArray *array =[[NSMutableArray alloc] init];    
//some lat and long values
NSDictionary *latLongDict = @{@"lat" : @(18.25689), @"long":@(48.25689)};

//add the objects to the array
[array addObject:latLongDict];

答案 2 :(得分:0)

您可以将数据存储在字典对象中:

NSMutableArray *locationArray =[[NSMutableArray alloc] init];

//some lat and long values
CGFloat latitude = 18.25689;
CGFloat longitude = 48.25689;

NSDictionary *locationDict = @{ @"latitude" : [NSNumber numberWithFloat:latitude], @"longitude" : [NSNumber numberWithFloat:longitude] };

[locationArray addObject:locationDict];

并通过以下方式访问它们:

NSUInteger anIndex = 0;
NSDictionary *locDict = [locationArray objectAtIndex:anIndex];
NSNumber *latitudeNumber = (NSNumber *)[locDict objectForKey:@"latitude"];
NSNumber *longitudeNumber = (NSNumber *)[locDict objectForKey:@"longitude"];

答案 3 :(得分:-1)

使用Mapkit框架,您可以找到当前位置以及靠近位置的纬度和位置。经度

 CLLocationCoordinate2D location;
 location = [mMapView.userLocation coordinate];

 if(iLat && iLng) 
 {

    location.latitude = [iLat floatValue];
    location.longitude = [iLng floatValue];
 }

在数组上存储值

NSMutableArray *a= [[NSMutableArray alloc] initWithObjects:location.latitude,location.longitude, nil];