2

如何存储多个点(纬度和经度)NSMutableArray

4

4 回答 4

6

你有几个选择:

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

于 2012-08-14T11:01:27.230 回答
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];
于 2012-08-14T11:09:41.623 回答
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"];
于 2013-10-07T10:58:01.723 回答
-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];
于 2012-08-14T11:07:23.597 回答