Reputation: 26223
So far I have been very impressed with Objective-C and the Cocoa Frameworks but I have to say that I am a little confused by the best way to create an array of CLLocationCoordinate2D to pass to the polylineWithCoordinates:count: I am pretty sure that this is how I need to setup the array.
NSUInteger numPoints = [locationData count];
CLLocationCoordinate2D *arrayPtr = malloc(numPoints * sizeof(CLLocationCoordinate2D));
But I am not sure how to access each location, I thought I could use arrayPtr[i] but I can't seem to get that to work properly.
for(NSUInteger counter=0; counter<numPoints; counter++) {
arrayPtr[counter] = [[locationData objectAtIndex:counter] coordinate];
}
I have it working now, I was viewing the memory wrong in the debugger, but is there another way (maybe without malloc) I did try encoding the values in an NSArray using NSValue, only to find that I need a c-type array instead :( any alternative methods would be most welcome.
Upvotes: 1
Views: 772
Reputation: 3358
That should be valid - what error are you getting?
A better approach might be to use CFArray instead of manually managing the malloc.
Upvotes: 1