-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Roslund/LocationLogging
Location logging
- Loading branch information
Showing
66 changed files
with
10,527 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
readme: readme.md | ||
github_url: https://github.com/Roslund/sequor | ||
theme: apple | ||
|
||
min_acl: internal | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import CoreLocation | ||
|
||
final class LocationLogger: NSObject, ObservableObject, CLLocationManagerDelegate { | ||
let locationManager = CLLocationManager() | ||
var trip: Trip | ||
|
||
init(trip: Trip) { | ||
self.trip = trip | ||
|
||
super.init() | ||
locationManager.delegate = self | ||
locationManager.requestAlwaysAuthorization() | ||
|
||
if CLLocationManager.locationServicesEnabled() { | ||
locationManager.desiredAccuracy = kCLLocationAccuracyBest | ||
locationManager.allowsBackgroundLocationUpdates = true | ||
// The minimum distance (measured in meters) a device must | ||
// move horizontally before an update event is generated. | ||
locationManager.distanceFilter = 5.0 | ||
locationManager.pausesLocationUpdatesAutomatically = false | ||
locationManager.showsBackgroundLocationIndicator = true | ||
locationManager.requestLocation() | ||
locationManager.startUpdatingLocation() | ||
} | ||
} | ||
|
||
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | ||
trip.locations += locations.map { location in | ||
Location(timestamp: location.timestamp, | ||
speed: location.speed, | ||
course: location.course, | ||
coordinate: Coordinate(latitude: location.coordinate.latitude, | ||
longitude: location.coordinate.longitude) | ||
) | ||
} | ||
} | ||
|
||
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { | ||
print(error) | ||
} | ||
|
||
func end() -> Trip { | ||
locationManager.stopUpdatingLocation() | ||
return trip | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Foundation | ||
|
||
/// Should represent a continuous travel on public transport. | ||
struct Trip: Codable { | ||
|
||
/// The date an time the tip started | ||
var startDate: Date = Date() | ||
|
||
/// The date an time the tip ended | ||
var endDate: Date? | ||
|
||
/// An array of locations captured durring the trip | ||
var locations: [Location] = [] | ||
} | ||
|
||
/// A GPS location | ||
struct Location: Codable { | ||
/// The timestam the location was recorded | ||
let timestamp: Date | ||
/// Speed at location (m/s) | ||
let speed: Double | ||
/// Course 0-359.9 degrees | ||
let course: Double | ||
/// The poistion | ||
let coordinate: Coordinate | ||
} | ||
|
||
/// Position represented by latitude and lognitude | ||
struct Coordinate: Codable { | ||
///The latitude in degrees. | ||
let latitude: Double | ||
///The longitude in degrees. | ||
let longitude: Double | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import SwiftUI | ||
|
||
/// A swiftUI wrapper around UIActivityViewController. | ||
/// Shows what commonly is refered to as the *ShareSheet*. | ||
/// We can use this to open and save data on device for easy onDevice debugging of tracking. | ||
/// - - - | ||
/// **Usage:** | ||
/// ```swift | ||
/// .sheet(isPresented: $showActivitySheet) { | ||
/// ActivityView(activityItems: [data], | ||
/// applicationActivities: nil) | ||
/// } | ||
/// ``` | ||
struct ActivityView: UIViewControllerRepresentable { | ||
|
||
let activityItems: [Any] | ||
var applicationActivities: [UIActivity]? | ||
|
||
func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityView>) -> UIActivityViewController { | ||
return UIActivityViewController(activityItems: activityItems, | ||
applicationActivities: applicationActivities) | ||
} | ||
|
||
func updateUIViewController(_ uiViewController: UIActivityViewController, | ||
context: UIViewControllerRepresentableContext<ActivityView>) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.