Class: IWCoordinateHistory

IWCoordinateHistory

A list of the last coordinates which can be used to determine the current course and speed.

Options used by this class:

Property Description Type Default
addDistanceThreshold coordinates closer to the last one than this threshold replace (i.e. correct) the last position, otherwise a new position is stored Number 5
maxListLength the maximal number of coordinates to store Number 20
courseDistanceThreshold minimal distance in meters used to calculate the course Number 30

Example:
Assuming you have a map called map you can calculate the current speed like this:

var coordinates = new IWCoordinateHistory({maxListLength: 10});

IWEventManager.addCustomListener(IWGeoLocationUtils, 'onpositionchange', function(event)
{
	coordinates.add(event.coordinate);
	console.log('Speed: ' + coordinates.calculateSpeed(4) * 3.6); // in km/h
});

IWGeoLocationUtils.track(map, {updateMap: false, enableHighAccuracy: true, timeout: 2000, showRadius: false });

new IWCoordinateHistory(options)

Creates a new coordinate history
Parameters:
Name Type Description
options object an object with properties as defined above

Methods


add(coordinate)

Adds another coordinate to the list, removing the oldest coordinate if the maximal length is exceeded. If the new coordinate is very close to the last one this will be replaced to correct the position.
Parameters:
Name Type Description
coordinate the new position
Returns:
Type
void

calculateCourse()

Calculates the course in degrees.
Returns:
Type
Number

calculateSpeed(numLocations)

Returns the average speed for the last numLocations GPS locations in meters per second.
Parameters:
Name Type Description
numLocations Number the number of GPS locations to take into account
Returns:
speed in m/s
Type
Number

getLatest()

Returns the latest coordinate, or null if there are no coordinates yet.
Returns:
Type
IWCoordinate