0.1.0 • Published 6 years ago

hafas-find-trip v0.1.0

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

hafas-find-trip

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

Location and bearing 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-trip

  • 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 of each vehicle into account.

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

Installation

npm install hafas-find-trip

Usage

If possible, provide location, bearing and product. An example from Berlin:

const query = {
	// U6 tunnel, northbound
	latitude: 52.496633,
	longitude: 13.390944,
	bearing: 16, // degrees, 0 is north
	product: 'subway'
}

If you don't provide the product, hafas-find-trip will instead apply its heuristic to all vehicles nearby. If you don't provide a bearing, it will estimate purely on the distance to the track of each vehicle.

const findTrip = require('hafas-find-trip')
const hafas = require('vbb-hafas')

findTrip(hafas, query)
.then((vehicle) => {
	console.log(vehicle.line.name, vehicle.direction, location)
})
.catch((err) => {
	console.error(err)
	process.exitCode = 1
})

Contributing

If you have a question or have difficulties using hafas-find-trip, 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.