npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hpsweb-bingmaps-distance

v1.0.1

Published

A simple node.js wrapper for Bingmaps's Distance API

Downloads

5

Readme

Bing Distance API for Node.js

Easily get traveling distance and duration data between locations with the Bingmaps Distance API

Installation

npm install hpsweb-bingmaps-distance

Usage

var distance = require("hpsweb-bingmaps-distance");

distance
  .get({
    origin: "San Francisco, CA",
    destination: "San Diego, CA",
  })
  .then(function (data) {
    console.log(data);
  })
  .catch(function (err) {
    console.log(err);
  });

The above example outputs the following data object:

{
  index: null,
  distance: '807 km',
  distanceValue: 807366,
  duration: '7 hours 30 mins',
  durationValue: 26981,
  origin: 'San Francisco, CA, USA',
  destination: 'San Diego, CA, USA',
  mode: 'driving',
  units: 'metric',
  language: 'en',
  avoid: null,
  sensor: false
}

Batch Mode

This example will return an array of data objects corresponding to all origin/destination pairs.

distance
  .get({
    origins: ["San Francisco, CA", "San Diego, CA"],
    destinations: ["San Diego, CA", "Seattle, WA"],
  })
  .then(function (data) {
    console.log(data);
  })
  .catch(function (err) {
    console.log(err);
  });

Result:

| Origin | Destination | | ----------------- | ------------- | | San Francisco, CA | San Diego, CA | | San Francisco, CA | Seattle, WA | | San Diego, CA | San Diego, CA | | San Diego, CA | Seattle, WA |

Additional Parameters

Here is a full list of options you can include to tailor your query:

  • origin, destination - name (eg. 'San Francisco, CA') | latitude/longitude (eg. '51.510652,-0.095444')
  • index - null (default) | specify an index for identification
  • mode - 'driving' (default) | 'walking' | 'bicycling'
  • units - 'km' (default) Kilometer(km)/Mile(mi) | 'imperial' miles/feet
  • avoid - null (default) | 'highways' | 'tolls' | 'ferry' | 'minimizeHighways' | 'minimizeTolls' | 'borderCrossing'
  • optimize - time (default) | distance | timeWithTraffic | timeAvoidClosure | Specifies what parameters to use to optimize the route.

Note: The units setting only affects the text displayed within distance fields.

distanceValue is always in meters, and durationValue is always in seconds.

More Examples

This example specifies mode and units:

distance
  .get({
    origin: "San Francisco, CA",
    destination: "Los Angeles, CA",
    mode: "bicycling",
    units: "imperial",
  })
  .then(function (data) {
    console.log(data);
  })
  .catch(function (err) {
    console.log(err);
  });

Outputs:

{
  index: null,
  distance: '499 mi',
  distanceValue: 802534,
  duration: '1 day 21 hours',
  durationValue: 161896,
  origin: 'San Francisco, CA, USA',
  destination: 'Los Angeles, CA, USA',
  mode: 'bicycling',
  units: 'imperial',
  language: 'en',
  avoid: null,
  sensor: false
}

Let's use latitude and longitude for our origin/destination and an index:

distance
  .get({
    index: 1,
    origin: "37.772886,-122.423771",
    destination: "37.871601,-122.269104",
  })
  .then(function (data) {
    console.log(data);
  })
  .catch(function (err) {
    console.log(err);
  });

Outputs:

{
  index: 1,
  distance: '21.9 km',
  distanceValue: 21946,
  duration: '21 mins',
  durationValue: 1251,
  origin: 'Octavia Boulevard, San Francisco, CA 94102, USA',
  destination: '2066-2070 University Avenue, Berkeley, CA 94704, USA',
  mode: 'driving',
  units: 'metric',
  language: 'en',
  avoid: null,
  sensor: false
}

API Keys

You can request a key by following these steps.

Specify an API key for use like this:

var distance = require("hpsweb-bingmaps-distance");
distance.apiKey = "API_KEY";

Business users can omit the API key and instead specify their business client and signature keys:

var distance = require("hpsweb-bingmaps-distance");
distance.businessClientKey = "CLIENT_KEY";
distance.businessSignatureKey = "SIGNATURE_KEY";

Running Tests

  1. Install the development dependencies:

    npm install

  2. Run the tests:

    npm test