Skip to content

Commit

Permalink
Revisions for demo app comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Archdoog committed Jan 15, 2024
1 parent 4c951d1 commit e572879
Show file tree
Hide file tree
Showing 5 changed files with 464 additions and 666 deletions.
5 changes: 4 additions & 1 deletion apple/DemoApp/Demo/NavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ struct NavigationView: View {
}

init() {
locationManager = SimulatedLocationProvider(location: initialLocation)
let simulated = SimulatedLocationProvider(location: initialLocation)
simulated.warpFactor = 10
locationManager = simulated

_ferrostarCore = ObservedObject(
wrappedValue: FerrostarCore(
valhallaEndpointUrl: URL(string: "https://api.stadiamaps.com/route/v1?api_key=\(APIKeys.shared.stadiaMapsAPIKey)")!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@
"revision" : "b8deecb8adc3b911de311ead5a13b98fbf2d7824"
}
},
{
"identity" : "maplibre-swiftui-dsl-playground",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stadiamaps/maplibre-swiftui-dsl-playground",
"state" : {
"branch" : "main",
"revision" : "39e1d896ac9e898242c91ffc7726b631a0eb187e"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version" : "509.0.2"
"revision" : "43c802fb7f96e090dde015344a94b5e85779eff1",
"version" : "509.1.0"
}
}
],
Expand Down
5 changes: 1 addition & 4 deletions apple/DemoApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
This project is a minimal demonstration of how to use [Ferrostar](https://github.com/stadiamaps/ferrostar)
in an iOS application.

Eventually we would like to merge this into the main repository,
but hit some [issues with local Swift packages](https://forums.swift.org/t/issue-with-local-binarytarget-and-local-package/68726).

## Quickstart

1. Sign up for a [free Stadia Maps account](https://client.stadiamaps.com/signup/?utm_content=ferrostar_ios&utm_campaign=ferrostar_demos&utm_source=github)
2. Go through property setup and create an API key.
3. Update the `Info.plist` (either via project settings or opening directly) with your API key.
3. Update the `API-Keys.plist` with your API key.
4. Run the app!

NOTES:
Expand Down
8 changes: 6 additions & 2 deletions apple/Sources/FerrostarCore/Location.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ extension LiveLocationProvider: CLLocationManagerDelegate {
}
}

/// Location provider for testing without relying on simulator location spoofing.
///
/// This allows for more granular unit tests.
public class SimulatedLocationProvider: LocationProviding, ObservableObject {

public var delegate: LocationManagingDelegate?
public private(set) var authorizationStatus: CLAuthorizationStatus = .authorizedAlways

public private(set) var simulationState: LocationSimulationState?
public var warpFactor: UInt64 = 1

@Published public var lastLocation: CLLocation? {
didSet {
Expand Down Expand Up @@ -127,7 +131,7 @@ public class SimulatedLocationProvider: LocationProviding, ObservableObject {
lastLocation = location
}

public func start(route: Route) throws {
public func startSimulating(route: Route) throws {
simulationState = try locationSimulationFromRoute(route: route.inner)
startUpdating()
}
Expand Down Expand Up @@ -159,7 +163,7 @@ public class SimulatedLocationProvider: LocationProviding, ObservableObject {
return
}

try await Task.sleep(nanoseconds: 50 * NSEC_PER_MSEC)
try await Task.sleep(nanoseconds: NSEC_PER_SEC / self.warpFactor)
let newState = advanceLocationSimulation(state: lastState, speed: .jumpToNextLocation)

if simulationState?.currentLocation == newState.currentLocation {
Expand Down
Loading

0 comments on commit e572879

Please sign in to comment.