Skip to content

Instantly share code, notes, and snippets.

@gilserrap
Created July 9, 2014 10:28
Show Gist options
  • Select an option

  • Save gilserrap/5988b982c3ae7f2ae081 to your computer and use it in GitHub Desktop.

Select an option

Save gilserrap/5988b982c3ae7f2ae081 to your computer and use it in GitHub Desktop.
Getting coordinates for a MKPolyline
- (void)testThis:(MKPolyline *)stepPolyline
{
//route is the MKRoute in this example
//but the polyline can be any MKPolyline
NSUInteger pointCount = stepPolyline.pointCount;
//allocate a C array to hold this many points/coordinates...
CLLocationCoordinate2D *routeCoordinates
= malloc(pointCount * sizeof(CLLocationCoordinate2D));
//get the coordinates (all of them)...
[stepPolyline getCoordinates:routeCoordinates
range:NSMakeRange(0, pointCount)];
//this part just shows how to use the results...
NSLog(@"route pointCount = %ld", pointCount);
for (int c=0; c < pointCount; c++)
{
NSLog(@"routeCoordinates[%d] = %f, %f",
c, routeCoordinates[c].latitude, routeCoordinates[c].longitude);
}
//free the memory used by the C array when done with it...
free(routeCoordinates);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment