Reputation: 584
How to store multiple points (latitude and longitude) in NSMutableArray
?
Upvotes: 2
Views: 6269
Reputation: 574
//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];
Upvotes: 1
Reputation: 928
You could store the data inside a dictionary object:
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];
and access them by:
NSUInteger anIndex = 0;
NSDictionary *locDict = [locationArray objectAtIndex:anIndex];
NSNumber *latitudeNumber = (NSNumber *)[locDict objectForKey:@"latitude"];
NSNumber *longitudeNumber = (NSNumber *)[locDict objectForKey:@"longitude"];
Upvotes: 0
Reputation: 1408
Using Mapkit framework you can find the current location along with near by location with their latitude & longitude
CLLocationCoordinate2D location;
location = [mMapView.userLocation coordinate];
if(iLat && iLng)
{
location.latitude = [iLat floatValue];
location.longitude = [iLng floatValue];
}
Store value on array
NSMutableArray *a= [[NSMutableArray alloc] initWithObjects:location.latitude,location.longitude, nil];
Upvotes: -1
Reputation: 16448
You've got a few options:
I'd recommend the latter, as you might find that you'll need the extra functionality on CLLocation later.
Upvotes: 6