Skip to content

johannes-bln/MapKitTools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MKTools

First of all, the code isn't good. But helps me a lot, that's why I share this.

Features

  • 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".

Installation

To install this package, follow these steps:

  1. Go to General -> Frameworks, Libraries, and Embedded Content.
  2. Click on the + button.
  3. Select Add Package Dependency... from the "Add More" dropdown.
  4. Paste the following URL in the top right: https://github.com/johannes-bln/MKTools.git.
  5. Click Add Package and then confirm by clicking Add Package in the next window.

Some samples:

Direction

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
                )
            }
        }
    }
}

Multiple Routes

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 ;)

About

Not perfect, but a helpful SPM package for map operations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages