Skip to content

Instantly share code, notes, and snippets.

@freak4pc
Last active October 10, 2023 07:44
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save freak4pc/98c813d8adb8feb8aee3a11d2da1373f to your computer and use it in GitHub Desktop.
Save freak4pc/98c813d8adb8feb8aee3a11d2da1373f to your computer and use it in GitHub Desktop.
Get a list of coordinates from a MKPolyline / MKRoute
public extension MKMultiPoint {
var coordinates: [CLLocationCoordinate2D] {
var coords = [CLLocationCoordinate2D](repeating: kCLLocationCoordinate2DInvalid,
count: pointCount)
getCoordinates(&coords, range: NSRange(location: 0, length: pointCount))
return coords
}
}
// Given a MKRoute, you can just do:
// route.polyline.coordinates
@BhamJack
Copy link

BhamJack commented May 4, 2017

Thanks, good reminder of being swifty and having bester code.

@KennethFra
Copy link

KennethFra commented Jun 12, 2018

Suggestion: Making the extension off of MKMultiPoint as both MKPolyline and MKPolygon are subclasses of MKMultipoint and can benefit from this extension.

@freak4pc
Copy link
Author

freak4pc commented Jul 8, 2018

@KennethFra - fair point! Thanks for that note.

@OhadMaor-VIA
Copy link

Awesome job! Thanks! :)

@StevenKowalzik
Copy link

This helped me a lot, thank you!

@rhunt222
Copy link

This is great, thank you!

@makinney
Copy link

Thanks for this code. Just what I needed. Working on get coordinates out of a geoJSON geometry object

@durkester
Copy link

Also wanted to add a thanks, still needed in April of 2022. Maybe WWDC22 we'll get some swiftui and mapkit improvements!

@qianzhonglue
Copy link

Thanks for this code, It's just for me. Great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment