JSPM

@mandrews6975/nav-urls

1.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q25295F
  • License MIT

Generate navigation URLs for various map platforms such as Google Maps.

Package Exports

  • @mandrews6975/nav-urls

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mandrews6975/nav-urls) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Contributors Forks Stargazers Issues MIT License


Logo

Nav-URLs

Generate navigation URLs for various map platforms such as Google Maps.

Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Installation
  3. Function Reference
  4. Usage
  5. License
  6. Contact
  7. Acknowledgements
  8. Open Source Licenses

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] to locations[n])
    • options
      • Type: {platform: 'google' | 'apple' | 'bing', travelmode: 'driving' | 'walking' | 'transit' | 'bicycling'}
        • Note: travelmode: 'bicycling' only supported by Google Maps
      • Description: object containing platform and travelmode
  • Returns:
    • Type: string
    • Description: raw-ordered navigation URL for the specified platform and locations

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)
    • 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
      • Description: object containing platform and travelmode
    • callback
      • Type: (navURL: string) => any
      • Description: function that will be called after the URL is retrieved (takes the optimized navigation URL as a parameter)

[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] to locations[n])
    • options
      • Type: {platform: 'google' | 'apple' | 'bing', travelmode: 'driving' | 'walking' | 'transit' | 'bicycling'}
        • Note: travelmode: 'bicycling' only supported by Google Maps
      • Description: object containing platform and travelmode
  • Returns:
    • Type: string
    • Description: raw-ordered navigation URL for the specified platform and locations

[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)
    • 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
      • Description: object containing platform and travelmode
  • Returns:
    • Type: string
    • Description: optimized navigation URL for the specified platform and locations

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: me@michaelandrews.dev

Project Link: https://github.com/mandrews6975/Nav-URLs

Acknowledgements

Open Source Licenses