distances

0.0.0-gamma • Public • Published

distances Build Status

Google's distance matrix API

The Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations, based on the recommended route between start and end points.

Install

$ npm install distances

Usage

import distances from 'distances';

(async () => {
  const res = await distances({
    units: 'imperial',
    origins: 'Washington, DC',
    destinations: 'New + York + City, NY',
    key: 'GOOGLE_KEY',
  });
  console.log(res);
})();

You will get as response

{
  destination: [ 'New York, NY, USA' ],
  origin: [ 'Washington, DC, USA' ],
  distance: '226 mi',
  distanceValue: 363999,
  duration: '3 hours 50 mins',
  durationValue: 13777
}

Read more about in Google's Docs.

API

distances([params])

params

Type: object

Required parameters

origins: The starting point for calculating travel distance and time.

Type: string
Examples:

  • Name: Washington, DC
  • Longitude and Latitude: 25.827200, -80.281500
destinations: One or more locations to use as the finishing point for calculating travel distance and time.

Type: string
Examples:

  • Name: Washington, DC
  • Longitude and Latitude: 25.827200, -80.281500
key: Your application's API key. This key identifies your application for purposes of quota management. Get a key

Optional parameters

mode: Specifies the mode of transport to use when calculating distance.

Type: string
Default: driving
Travel modes: driving | walking | bicycling | transit

language: The language in which to return results.

Type: string

region: The region code, specified as a ccTLD (country code top-level domain) two-character value.

Type: string

avoid: Introduces restrictions to the route.

Type: string

units: Specifies the unit system to use when expressing distance as text.

License

MIT © Abraham Hernandez

Readme

Keywords

none

Package Sidebar

Install

npm i distances

Weekly Downloads

4

Version

0.0.0-gamma

License

MIT

Unpacked Size

4.6 kB

Total Files

4

Last publish

Collaborators

  • abranhe