如何在NSMutableArray
?
答案 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];