First of all, the code isn't good. But helps me a lot, that's why I share this.
- getRoute: Calculate a simple Route from A to B.
- getRoutes: Calculates possible Routes from A to B - return all as a [Array]
- search: Search for Locations -> This has no Ratelimit (but to get full data of the location use getPlacemark.
- getPlacemark: Converts a Location Search Result to a "Placemark".
To install this package, follow these steps:
- Go to General -> Frameworks, Libraries, and Embedded Content.
- Click on the + button.
- Select Add Package Dependency... from the "Add More" dropdown.
- Paste the following URL in the top right:
https://github.com/johannes-bln/MKTools.git. - Click Add Package and then confirm by clicking Add Package in the next window.
import SwiftUI
import MKTools
import CoreLocation
struct ContentView: View {
@StateObject private var mkTools = MKTools()
var body: some View {
VStack {
List(mkTools.directions, id: \.self) { direction in
Text(direction)
}
.task {
await mkTools.getRoute(
start: CLLocationCoordinate2D(latitude: 52.5200, longitude: 13.4050),
destination: CLLocationCoordinate2D(latitude: 48.8566, longitude: 2.3522),
transportType: .automobile
)
}
}
}
}import SwiftUI
import MKTools
import MapKit
struct ContentView: View {
@StateObject private var mkTools = MKTools()
var body: some View {
VStack {
Map() {
ForEach(mkTools.multipleRoutes, id: \.self) { routes in
MapPolyline(routes)
.stroke(.green, lineWidth: 12)
}
}
.task {
await mkTools.getRoutes(
start: CLLocationCoordinate2D(latitude: 52.5200, longitude: 13.4050),
destination: CLLocationCoordinate2D(latitude: 48.8566, longitude: 2.3522),
transportType: .automobile
)
}
}
}
}
#Preview {
ContentView()
}and much more ;)