@mandrews6975/nav-urls
v1.1.1
Published
Generate navigation URLs for various map platforms such as Google Maps.
Downloads
11
Maintainers
Readme
About The Project
Nav-URLs generates navigation URLs for various map platforms. Currently, supported platforms include Google Maps, Apple Maps, and Bing Maps. Navigation routes can be generated by raw ordering or distance optimization. Generation of optimized navigation route URLs requires a MapQuest Developer API key. You can register and obtain a free MapQuest API key here.
Built With
Installation
Install via NPM:
npm install @mandrews6975/nav-urls
Function Reference
There are two preferred functions for generating navigation URLs (raw-ordered and optimized) and two deprecated functions that provide essentially the same functionality.
getRouteURL(locations, options)
Returns a raw-ordered navigation URL for the specified platform and locations.
- Parameters
- locations
- Type:
string[]
- Description: locations/addresses written in formats standard map platforms understand (route is ordered from
locations[0]
tolocations[n]
)
- Type:
- options
- Type:
{platform: 'google' | 'apple' | 'bing', travelmode: 'driving' | 'walking' | 'transit' | 'bicycling'}
- Note:
travelmode: 'bicycling'
only supported by Google Maps
- Note:
- Description: object containing platform and travelmode
- Type:
- locations
- Returns:
- Type:
string
- Description: raw-ordered navigation URL for the specified platform and locations
- Type:
getOptimizedRouteURL(locations, key, options, callback)
Retrieves an optimized navigation URL for the specified platform and locations and passes said URL into its callback function.
- Parameters
- locations
- Type:
string[]
- Description: array of locations/addresses written in formats standard map platforms understand (
locations[0]
is origin,locations[n]
is destination,locations[1..n-1]
are waypoints to be optimized)
- Type:
- key: string that is a MapQuest API key (register for a free key here)
- options
- Type:
{platform: 'google' | 'bing', travelmode: 'driving' | 'walking' | 'transit' | 'bicycling'}
- Note:
travelmode: 'bicycling'
only supported by Google Maps
- Note:
- Description: object containing platform and travelmode
- Type:
- callback
- Type:
(navURL: string) => any
- Description: function that will be called after the URL is retrieved (takes the optimized navigation URL as a parameter)
- Type:
- locations
[DEPRECATED] routeNav(locations, options)
Returns a raw-ordered navigation URL for the specified platform and locations.
- Parameters
- locations
- Type:
string[]
- Description: locations/addresses written in formats standard map platforms understand (route is ordered from
locations[0]
tolocations[n]
)
- Type:
- options
- Type:
{platform: 'google' | 'apple' | 'bing', travelmode: 'driving' | 'walking' | 'transit' | 'bicycling'}
- Note:
travelmode: 'bicycling'
only supported by Google Maps
- Note:
- Description: object containing platform and travelmode
- Type:
- locations
- Returns:
- Type:
string
- Description: raw-ordered navigation URL for the specified platform and locations
- Type:
[DEPRECATED] routeNavOpt(locations, key, options)
Returns an optimized navigation URL (string) for the specified platform and locations.
- Parameters
- locations
- Type:
string[]
- Description: array of locations/addresses written in formats standard map platforms understand (
locations[0]
is origin,locations[n]
is destination,locations[1..n-1]
are waypoints to be optimized)
- Type:
- key: string that is a MapQuest API key (register for a free key here)
- options
- Type:
{platform: 'google' | 'bing', travelmode: 'driving' | 'walking' | 'transit' | 'bicycling'}
- Note:
travelmode: 'bicycling'
only supported by Google Maps
- Note:
- Description: object containing platform and travelmode
- Type:
- locations
- Returns:
- Type:
string
- Description: optimized navigation URL for the specified platform and locations
- Type:
Usage
Example 1
Print raw-ordered Google Maps navigation URL to console:
const nav = require('@mandrews6975/nav-urls');
let locations = [
'Denver',
'New York City',
'Des Moines, IA',
"Devil's Tower",
'Duck Key',
];
let options = {
platform: 'google',
travelmode: 'driving',
};
console.log(nav.getRouteURL(locations, options));
Result:
https://www.google.com/maps/dir/?api=1&origin=Denver&destination=Duck%20Key&travelmode=driving&waypoints=New%20York%20City%7CDes%20Moines%2C%20IA%7CDevil%27s%20Tower
Example 2
Print optimized Google Maps navigation URL to console:
let locations = [
'Denver',
'New York City',
'Des Moines, IA',
"Devil's Tower",
'Duck Key',
];
let options = {
platform: 'google',
travelmode: 'driving',
};
let key = 'mapquest_api_key';
nav.getOptimizedRouteURL(locations, key, options, (navURL) =>
console.log(navURL)
);
Result:
https://www.google.com/maps/dir/?api=1&origin=Denver&destination=Duck%20Key&travelmode=driving&waypoints=Devil%27s%20Tower%7CDes%20Moines%2C%20IA%7CNew%20York%20City
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Michael Andrews - GitHub: mandrews6975 - Email: [email protected]
Project Link: https://github.com/mandrews6975/Nav-URLs