在 NSMutableArray Xcode 中存储纬度和经度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11950783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Store latitude and longitude in NSMutableArray Xcode
提问by fadd
How to store multiple points (latitude and longitude) in NSMutableArray
?
如何存储多个点(纬度和经度)NSMutableArray
?
采纳答案by mangesh
//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];
回答by joerick
You've got a few options:
你有几个选择:
- Create your own object with latitude and longitude properties and store this
- Use the CLLocationCoordinate2Dstruct and wrap it in an NSValueobject
- Use the CLLocationobject
- 使用纬度和经度属性创建您自己的对象并存储它
- 使用CLLocationCoordinate2D结构并将其包装在NSValue对象中
- 使用CLLocation对象
I'd recommend the latter, as you might find that you'll need the extra functionality on CLLocation later.
我推荐后者,因为您可能会发现稍后您将需要 CLLocation 上的额外功能。
回答by Phil Wilson
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"];
回答by Prabhjot Singh Gogana
Using Mapkit framework you can find the current location along with near by location with their latitude & longitude
使用 Mapkit 框架,您可以找到当前位置以及附近位置及其纬度和经度
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];