Skip to content

swift async await streamer asynclocation kit ios map swift tracker, user current geolocation and geocoding, gps, swiftui map example using MapKit address decoder Corelocation based service in swift Async stream pattern for CoreBluetooth Example app Apple maps Map swiftui watchos, location service manager, geocoder detect gps coord εœ°η‚Ή 場所

License

Notifications You must be signed in to change notification settings

swiftuiux/swift-async-corelocation-streamer

 
 

Repository files navigation

Async location streamer using new concurrency model in Swift

Features

  • Using new concurrency swift model around CoreLocation
  • Streaming current locations asynchronously
  • Customizable in terms of accuracy
  • Errors handling

How to use

1. Add to info the option "Privacy - Location When In Use Usage Description"

Stories life circle

2. Add or inject LMViewModel into a View

    @EnvironmentObject var model: LMViewModel

3. call ViewModel method start() within async environment of the View

             Task{
                 do{
                     try await model.start()
                 }catch{
                     self.error = error.localizedDescription
                 }
             }

4. Process async stream of locations from "locations" property of the ViewModel

    @ViewBuilder
    var coordinatesTpl: some View{
        List(viewModel.locations, id: \.hash) { location in
            Text("\(location.coordinate.longitude), \(location.coordinate.latitude)")
        }
    }

5. Showcase possible errors from LMViewModel in UI is up to you

    ///Status is not determined If you are trying to get Async stream without
     permission request in case you implement your own ViewModel and access LocationManagerAsync.locations
    case statusIsNotDetermined
    
    ///Access was denied by  user
    case accessIsNotAuthorized

ViewModel API

public protocol ILocationManagerViewModel: ObservableObject{
        
    /// List of locations
    @MainActor
    var locations : [CLLocation] { get }
    
    /// Start streaming locations
    func start() async throws
    
    /// Stop streaming locations
    func stop() async
}

SwiftUI example of using package

d3-stories-instagram-example

if you are using the simulator don't forget to simulate locations

Stories life circle

Documentation(API)

  • You need to have Xcode 13 installed in order to have access to Documentation Compiler (DocC)
  • Go to Product > Build Documentation or βŒƒβ‡§βŒ˜ D

About

swift async await streamer asynclocation kit ios map swift tracker, user current geolocation and geocoding, gps, swiftui map example using MapKit address decoder Corelocation based service in swift Async stream pattern for CoreBluetooth Example app Apple maps Map swiftui watchos, location service manager, geocoder detect gps coord εœ°η‚Ή 場所

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages