简体   繁体   中英

How to create a CLLocationCoordinate2d object

I am trying to to call MKPolylines' + polylineWithCoordinates:count: method.

How can I create a CLLocationCoordinate2D * object in this case. I have gone through this particular answer in CLLocationCoordinate2D without knowing how many will be in the array?

// unpacking an array of NSValues into memory
CLLocationCoordinate2D *points = malloc([mutablePoints count] * sizeof(CLLocationCoordinate2D));
for(int i = 0; i < [mutablePoints count]; i++) {
[[mutablePoints objectAtIndex:i] getValue:(points + i)];
}

MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:points count:[mutablePoints count]];
free(points);

What kind of entries are in the array mutablePoints in the above case?

If your question is simply what kind of entries are in the array, the answer is quite simple: NSValue entries. You can have a look at this guide for more info on how to use NSValues .

CLLocationCoordinate2D coordinate;
    for (int i = 0; i < arr.count; i++)
    {
        float t1 = [[arr objectAtIndex:1] floatValue];
        float t2 = [[arr objectAtIndex:0] floatValue];

        coordinate.latitude = t1;
        coordinate.longitude = t2;

    }

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