Skip to content

Instantly share code, notes, and snippets.

@yllan
Created June 19, 2019 03:17
Show Gist options
  • Save yllan/1595acebf298ef7e97f3660365f155aa to your computer and use it in GitHub Desktop.
Save yllan/1595acebf298ef7e97f3660365f155aa to your computer and use it in GitHub Desktop.
Encode MKPolyline to Data
func encode(line: MKPolyline) -> Data {
return Data(buffer: UnsafeBufferPointer(start: line.points(), count: line.pointCount))
}
func decode(data: Data) -> MKPolyline {
let buf = UnsafeMutableBufferPointer<MKMapPoint>.allocate(capacity: data.count / MemoryLayout<MKMapPoint>.size)
data.copyBytes(to: buf)
return MKPolyline(points: buf.baseAddress!, count: buf.count)
}
@rollr76518
Copy link

跪了

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