I have an encoded polyline created by the Mapbox javascript API (https://github.com/mapbox/polyline) and I would like to decode this polyline into a list of coordinates (or even just an MGLShape
) on the iOS app.
I attempted to decode directly to an MGLShape
(note: this is totally wrong as I got mixed up with the encoded polyline and GeoJSON, which is what the MGLShape(data:)
is looking for.)
if let shapeData = "_nwfFteckVd@rIvEhEaB~Ht@lIxD~EvE~DfB|HdCeHrBwHnGT|ExDbGzAjGAyC{GjG[fGbA~@iICuIjG@lFqCrBpHj@lIaClHmGOiEbFVvIkCdHgEdFkGImGQoFbDgGgAmGl@iG_@}F_CmCgHZuI`@wIy@oIk@oI|BkH}EgE}BmH".data(using: .utf8) {
MGLPolyline
let shape = try? MGLShape(data: shapeData, encoding: String.Encoding.utf8.rawValue)
let shapeSource = MGLShapeSource(identifier: "polyLineSource", shape: shape, options: nil)
}
But shape
comes out nil
.
I didn't see any way with the Mapbox API to decode this polyline in coordinates easily.