Returns the heading on a particular point in time.
When the trip was supposed to start.
Current time.
Vehicle's current heading in degrees.
Returns the position on a particular point in time.
When the trip was supposed to start.
Current time.
Vehicle's current position.
Returns the total traveled distance on a particular point in time.
When the trip was supposed to start.
Current time.
Vehicle's current traveled distance.
Whether the trip has ended based on an specific point in time.
When the trip was supposed to start.
Current time.
Whether is has ended or not.
Generated using TypeDoc
A single Trip defines a path from one point to another. It returns the vehicle position and heading based on a specific speed, a start date and the current date.
// From - To. The two points are 10km appart. const a = new google.maps.LatLng(20.65273901635008, -103.44528316226638) const b = new google.maps.LatLng(20.693668019183118, -103.35969321162369) // Creating new Trip: // - 190° start heading // - 10 km/h speed const trip = new Mapster.Trip(a, b, 190, 10) // Printing the distance our vehicle has traveled each 15 minutes. Since we are doing 10km at 10km/h we should be getting 2.5km every 15 minutes. const startTimestamp = new Date('2000-01-01 08:00').getTime() const splits = [] new Array(5).fill(0).forEach((t, i) => { const currentTimestamp = startTimestamp + (15 * 1000 * 60) * i const distance = trip.getTraveledDistance(startTimestamp, currentTimestamp) const position = trip.getPositionInTime(startTimestamp, currentTimestamp) const heading = trip.getHeadingInTime(startTimestamp, currentTimestamp) splits.push({ time: new Date(currentTimestamp).toLocaleTimeString(), distance: (distance / 1000).toFixed(1), lat: position.lat().toFixed(2), lng: position.lng().toFixed(2), heading: heading.toFixed(0), }) }) console.table(splits)As you can see, the first snapshot still has a 190 heading angle but second snapshot does not. That's because the trip mannager first task is to move the vehicle heading angle in point B's direction. It might take a houndrer of milliseconds to get to the final heading angle.