Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build
run: swift build
- name: Test
Expand All @@ -21,12 +21,12 @@ jobs:

strategy:
matrix:
swift: ["5.9.1", "5.7.3"]
swift: ["6.0", "5.10", "5.9", "5.8"]

container:
image: swift:${{ matrix.swift }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build
run: swift build
- name: Test
Expand Down
63 changes: 63 additions & 0 deletions Sources/GeoJSONKitTurf/GeoJSON+LineString+DecodePolyline.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// GeoJSON+LineString+DecodePolylineString.swift
//
// Created by Adrian Schoenig on 18/2/17.
//
//
import Foundation

import GeoJSONKit

extension GeoJSON.LineString {
public init(encodedPolyline: String) {
let bytes = encodedPolyline.utf8CString
let length = bytes.count - 1 // ignore 0 at end
var idx = 0

var array: [GeoJSON.Position] = []

var latitude = 0.0
var longitude = 0.0
while idx < length {
var byte = 0
var res = 0
var shift = 0

repeat {
if idx > length {
break
}
byte = Int(bytes[idx]) - 63
idx += 1
res |= (byte & 0x1F) << shift
shift += 5
} while byte >= 0x20

let deltaLat = ((res & 1) != 0 ? ~(res >> 1) : (res >> 1));
latitude += Double(deltaLat)

shift = 0
res = 0

repeat {
if idx > length {
break
}
byte = Int(bytes[idx]) - 0x3F
idx += 1
res |= (byte & 0x1F) << shift
shift += 5
} while byte >= 0x20

let deltaLon = ((res & 1) != 0 ? ~(res >> 1) : (res >> 1));
longitude += Double(deltaLon)

let finalLat = latitude * 1E-5
let finalLon = longitude * 1E-5
let coordinate = GeoJSON.Position(latitude: finalLat, longitude: finalLon)
array.append(coordinate)
}

self.init(positions: array)
}
}