简体   繁体   中英

How to convert NSMutableArray to CLLocationCoordinate2D

I have NSMutableArray:

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

        NSLog(@"%@",userCoordinates);

NSLog shows:

(
    "19.365367",
    "-99.159887"
)

Then I need to convert this array to CllocationCoordinate2D to use it for create annotation. 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 :

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM