google_directions
This NPM Module is the simplest interface for asynchronously querying the Google Directions API (https://developers.google.com/maps/documentation/directions/intro) via Node. Find more information about the API here: https://developers.google.com/maps/documentation/directions/intro.
Installation
npm i google_directions
Get a Google API Key
https://console.developers.google.com/flows/enableapi?apiid=directions_backend&keyType=SERVER_SIDE
- Select/Create a Project
- Enable Directions API
- Generate a Key (See the Credentials Tab)
Usage
Include this. Here are the parameter details.
var map = ; var params = // REQUIRED origin: "" destination: "" key: "" // OPTIONAL mode: "" avoid: "" language: "" units: "" region: "";
API Methods
There are six main methods to choose from.
Raw Google Direction API Response (JSON):
// get the raw Google Directions API response as JSON objectmap;
Navigation Steps (JSON):
// get navigation steps as JSON objectmap;
Total Distance (String):
// get total distance as stringmap;
Total Duration (String):
// get total duration as stringmap;
Starting Address (String):
// get the starting address as stringmap;
Destination Address (String):
// get the destination address as stringmap;
Parameters
- origin: staring location
- destination: ending location
- key: your Google-generated API key
- mode: “driving” | “walking” | “bicycling”
- default: driving
- avoid: "tolls" | "highways" | "ferries" | "indoor"
- default: none
- language: https://developers.google.com/maps/faq#languagesupport
- default: based on origin country
- units: "metric" | "imperial"
- default: based on origin country
- region: https://developers.google.com/maps/documentation/directions/intro#RegionBiasing
- default: based on location of user
History
Still currently maintained and updated.
- 0.2.0 Initial Release
Credits
License
MIT License