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.
$ npm install distances
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.
Type: object
Required parameters
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
Type: string
Default: driving
Travel modes: driving
| walking
| bicycling
| transit
Type: string
Type: string
Type: string
MIT © Abraham Hernandez