Expand description
Tools for simulating progress along a route.
§Example
Here’s an example usage with the polyline constructor.
This can serve as a template for writing your own test code.
You may also get some inspiration from the Swift
or Kotlin
SimulatedLocationProvider implementations which wrap this.
use ferrostar::simulation::{advance_location_simulation, location_simulation_from_polyline, LocationBias};
let polyline_precision = 6;
// Build the initial state from an encoded polyline.
// You can create a simulation from coordinates or even a [Route] as well.
let mut state = location_simulation_from_polyline(
"wzvmrBxalf|GcCrX}A|Nu@jI}@pMkBtZ{@x^_Afj@Inn@`@veB",
polyline_precision,
// Passing `Some(number)` will resample your polyline at uniform distances.
// This is often desirable to create a smooth simulated movement when you don't have a GPS trace.
None,
LocationBias::None,
)?;
loop {
let mut new_state = advance_location_simulation(&state);
if new_state == state {
// When the simulation reaches the end, it keeps yielding the input state.
break;
}
state = new_state;
// Do something; maybe sleep for some period of time until the next timestamp?
}Structs§
- Location
Simulation State - The current state of the simulation.
Enums§
- Location
Bias - Controls how simulated locations deviate from the actual route line. This simulates real-world GPS behavior where readings often have systematic bias.
- Simulation
Error
Functions§
- advance_
location_ simulation - Returns the next simulation state based on the desired strategy. Results of this can be thought of like a stream from a generator function.
- location_
simulation_ from_ coordinates - Creates a location simulation from a set of coordinates.
- location_
simulation_ from_ polyline - Creates a location simulation from a polyline.
- location_
simulation_ from_ route - Creates a location simulation from a route.