简体   繁体   English

如何将NSMutableArray转换为CLLocationCoordinate2D

[英]How to convert NSMutableArray to CLLocationCoordinate2D

I have NSMutableArray: 我有NSMutableArray:

        userCoordinates = [[d objectForKey:@"geo"] objectForKey:@"coordinates"];

        NSLog(@"%@",userCoordinates);

NSLog shows: NSLog显示:

(
    "19.365367",
    "-99.159887"
)

Then I need to convert this array to CllocationCoordinate2D to use it for create annotation. 然后,我需要将此数组转换为CllocationCoordinate2D,以将其用于创建注释。 Sorry my english. 对不起,我的英语。 Thanks. 谢谢。

It seems that your array contains two NSString objects - to convert them to the appropriate floating-point numbers, use the doubleValue method of NSString : 看来您的数组包含两个NSString对象-要将它们转换为适当的浮点数,请使用NSStringdoubleValue方法:

double lat = [(NSString *)[userCoordinates objectAtIndex:0] doubleValue];
double lon = [(NSString *)[userCoordinates objectAtIndex:1] doubleValue];

CLLocationCoordinate2D coords = (CLLocationCoordinate2D){ lat, lon };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CLLocationCoordinate2D和NSMutableArray - CLLocationCoordinate2D and NSMutableArray 如何将NSValue转换为CLLocationCoordinate2D - How to Convert NSValue to CLLocationCoordinate2D 如何从Dynamic NSMutableArray将坐标添加到CLLocationCoordinate2D? - How to add Coordinates to CLLocationCoordinate2D from Dynamic NSMutableArray? 转换UnsafeMutablePointer <CLLocationCoordinate2D> 到Swift中的[CLLocationCoordinate2D] - Convert UnsafeMutablePointer<CLLocationCoordinate2D> to [CLLocationCoordinate2D] in Swift 无法将CLLocationCoordinate2D转换为(CLLocationCoordinate2D) - Cannot convert CLLocationCoordinate2D to (CLLocationCoordinate2D) MKPolygon - 如何确定 CLLocationCoordinate2D 是否在 CLLocationCoordinate2D 多边形中? - MKPolygon - How to determine if a CLLocationCoordinate2D is in a CLLocationCoordinate2D polygon? 如何存储CLLocationCoordinate2D? - How to store CLLocationCoordinate2D? Swift:如何将 CGPoint 转换为 CLLocationCoordinate2D - Swift: How do you convert CGPoint to CLLocationCoordinate2D 将CLLocation或CLLocationCoordinate2D转换为CGPoint - Convert CLLocation or CLLocationCoordinate2D to CGPoint 将 CLLocationCoordinate2D(s) 的字符串转换为数组 - Convert String of CLLocationCoordinate2D(s) into array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM