如何在NSMutableArray
中存储多个点(经度和纬度)?在NSMutableArray中存储经度和纬度Xcode
2
A
回答
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];
+0
如果你要这样做,NSNumber会更合适。但在我看来,把这个对作为单独的实体存储在数组中是没有意义的。 – joerick 2012-08-14 11:26:31
6
你有几种选择:
- 创建经度和纬度的属性你自己的对象,并存储该
- 使用CLLocationCoordinate2D结构,并在NSValue对象
- 使用CLLocation把它包对象
我推荐后者,因为你可能会发现你需要CLLocation la上的额外功能之三。
-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];
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"];
相关问题
- 1. 存储路线的经度和纬度
- 2. 检查图像中是否存在经度和纬度经度和纬度
- 3. 如何在Android中“存储”经纬度?
- 4. GeoShape不存储纬度/经度
- 5. 如何在MySQL中存储纬度和经度?
- 6. 无法将经度和纬度存储在变量中
- 7. 将地标的经度和纬度存储到数组中
- 8. xcode:打印MKMapView地区,跨度,纬度经度,纬度
- 9. Googlemap和纬度和经度
- 10. 纬度和经度的数据类型和存储格式
- 11. 如何在xcode中查找mapview的经度和纬度?
- 12. 如何在MySQL数据库中存储纬度/经度
- 13. 偏向经度和纬度
- 14. 纬度和经度Java
- 15. 将经度和纬度
- 16. 转换经度和纬度
- 17. 查找经度和纬度
- 18. 经度和纬度NullPointerException
- 19. 纬度和经度半径
- 20. 绘制经度和纬度
- 21. php exif;纬度和经度?
- 22. JavaScript的纬度和经度
- 23. 获取纬度和经度
- 24. MySql的纬度和经度
- 25. 获取经度和纬度
- 26. 纬度和经度问题
- 27. 安卓纬度和经度
- 28. 地图经度和纬度
- 29. 纬度和经度地址
- 30. 经度和纬度转换
请搜索,发布问题之前。这是一种创建二维数组的方法http://stackoverflow.com/questions/724772/2d-arrays-in-objective-c – 2012-08-14 11:02:29
@SharonNathaniel这不是一个关于二维数组的问题。经度和纬度不是整数,它们不能用作数组的指示。 – joerick 2012-08-14 11:28:59