Skip to content

Provide location and bearing, get a list of vehicles you're most likely in.

License

Notifications You must be signed in to change notification settings

derhuerst/hafas-find-trips

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hafas-find-trips

Provide location and bearing/heading, get the public transport vehicle you're most likely in.

Location and bearing/heading are expected to be inaccurate because they come from a mobile device. Also, The vehicle movements from the underlying radar() API are often not the actual position, but the estimated position, based on their current delays and their track. To compensate for this, hafas-find-trips

  • filters by product if you provide one,
  • checks if the location is close to where vehicles have recently been or will soon be,
  • takes the bearing/heading of each vehicle into account.

npm version ISC-licensed chat with me on Gitter support me on Patreon

Installation

npm install hafas-find-trips

Usage

Provide a track of user locations from the last ~10 seconds as GeoJSON LineString. If possible, provide a product in addition.

const findTrips = require('hafas-find-trips')
const createHafas = require('vbb-hafas')

const hafas = createHafas('my-awesome-program')

findTrips(hafas, {
	recording: {
		type: 'Feature',
		properties: {},
		geometry: { // GeoJSON LineString
			type: 'LineString',
			coordinates: [ /* … */ ]
		}
	},
	product: 'subway' // optional
})
.then((matches) => {
	for (let match of matches) {
		const m = match.movement
		console.log(match.score, m.line.name, m.direction, m.location)
	}
})
.catch((err) => {
	console.error(err)
	process.exitCode = 1
})

If you don't provide the product, it will instead apply its heuristic to all vehicles nearby.

Contributing

If you have a question or have difficulties using hafas-find-trips, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.