The polylineWithCoordinates method requires a simple array of C structures of type CLLocationCoordinate2D .
After calling valueForKeyPath , coordinateArray is an NSArray objects.
This is not the same as a C-array of structures.
Casting, which from NSArray to (CLLocationCoordinate2D *) does not convert it to an array of C structures.
Instead, you need to create the C array manually using malloc and loop through the locationRecoder array:
CLLocationCoordinate2D *coordinateArray = malloc(sizeof(CLLocationCoordinate2D) * locationRecorder.count); int caIndex = 0; for (CLLocation *loc in locationRecorder) { coordinateArray[caIndex] = loc.coordinate; caIndex++; } MKPolyline *lines = [MKPolyline polylineWithCoordinates:coordinateArray count:locationRecorder.count]; free(coordinateArray); [self.map addOverlay:lines];
source share