1.1.2 • Published 7 years ago

tfl-journey-planner v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Node TFL Journey Planner

A simple Node wrapper for the for fetching real-time journey's from the TFL API

dependencies Status devDependencies Status npm Codacy Badge

Install

npm install tfl-journey-planner --save

Usage

tflJourneyPlanner = require('tfl-journey-planner');

// Specify locations in this format
locations = {
  to: {lat: 51.5002452, lng: 0.0035842},
  from: {lat: 51.5131652, lng: -0.0905267}
};

options = {}; // Specify additional options if you want (see below)

tflJourneyPlanner(locations, options, function(results){
  console.log(results); // Do awesome stuff with the TFL results!
});

Locations

Locations can either be specified like:

locations = {
  to: {lat: 51.5002452, lng: 0.0035842},
  from: {lat: 51.5131652, lng: -0.0905267}
}

or with their text value

locations = {
  to: 'Aldgate East',
  from: 'London Bridge'
};

However, using text values will more than likley have many matches, so your response may not be as you'd planned.

or with postal codes/ text addresses

locations = {
  to: 'SE18 7PH',
  from: 'EC3M 3AD'
};

Specifying additional options

The second param is a JSON object where you can put any of the following (all are optional):

OPTIONDEFAULTEXPLINATION
viaTravel through (if in coordinate format then must be "longitude,latitude")
nationalSearchFalseDoes the journey cover stops outside London? eg. "nationalSearch=true"
dateThe date must be in yyyyMMdd format
timeThe time must be in HHmm format
timeIsDepartingDoes the time given relate to arrival or leaving time? Possible options: "departing""arriving"
journeyPreferenceLeastTimeThe journey preference eg possible options: "leastinterchange""leasttime""leastwalking"
modeThe mode must be a comma separated list of modes. eg possible options: "public-bus,overground,train,tube,coach,dlr,cablecar,tram,river,walking,cycle"
accessibilityPreferenceThe accessibility preference must be a comma separated list eg. "noSolidStairs,noEscalators,noElevators,stepFreeToVehicle,stepFreeToPlatform"
fromNameFrom name is the location name associated with a from coordinate
toNameTo name is the label location associated with a to coordinate
viaNameVia name is the location name associated with a via coordinate.
maxTransferMinutesThe max walking time in minutes for transfer eg. "120"
maxWalkingMinutesThe max walking time in minutes for journeys eg. "120"
walkingSpeedAverageThe walking speed. eg possible options: "slow""average""fast".
cyclePreferenceNoneThe cycle preference. eg possible options: "allTheWay""leaveAtStation""takeOnTransport""cycleHire"
adjustmentTime adjustment command. eg possible options: "TripFirst""TripLast"
bikeProficiencyA comma separated list of cycling proficiency levels. eg possible options: "easy,moderate,fast"
alternativeCycleFalseOption to determine whether to return alternative cycling journey
alternativeWalkingTrueOption to determine whether to return alternative walking journey
applyHtmlMarkupFalseFlag to determine whether certain text (e.g. walking instructions) should be output with HTML tags or not.
useMultiModalCallFalseA boolean to indicate whether or not to return 3 public transport journeys, a bus journey, a cycle hire journey, a personal cycle journey and a walking journey
walkingOptimizationFalseA boolean to indicate whether to optimize journeys using walking

Specify options like this:

options = {
    walkingOptimization: true,
    bikeProficiency: 'easy',
    accessibilityPreference: 'noEscalators'
}

Developing

Written in LiveScript, run npm run build to build, or npm run watch to watch for changes then build

Unit Tests

npm test

Issues

Report on GitHub repo issue page

Authenticating

Authentication is not required any longer or tfl requests. If you do need to authenticate then you can sign up for an API key at https://api-portal.tfl.gov.uk/signup Create a JSON object similar to the one below

    tfl = {
        appId: 'xxxxxxxx',
        appKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    };
1.1.2

7 years ago

1.1.0

7 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago