Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

compute-distance

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compute-distance

Find the distance represented by a set of points, filter if necessary

Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

Find the distance associated with an array of geospatial coordinates.

There are three methods associated with this library. Each takes an options param, where you can pass your Google Maps API object (using this library, for example).

filter(data, options)

A filter designed to smooth abberations from a GPS trace. It discards coordinates with accuracy less than 20 meters and coordinates that are more than 20 meters from their nearest neighbor.

Each object in the array should have the following attributes set:

{
  longitude: Double,
  latitude: Double,
  accuracy: Double // optional
}

mapToGoogle(data, options)

Take an array of coordinates and convert them to google.maps.LatLng objects.

Each object in the array should have the following attributes set:

{
  longitude: Double,
  latitude: Double
}

computeDistance(data, options)

Take an array of google.maps.LatLng objects and compute the distance they represent in meters.

Usage

This library depends on the Google Maps Javascript API, so be sure to include it using the directions on this page.

To filter a set of data before computing distance, use the following code:

var Distance = require('compute-distance');
var GoogleMapsLoader = require('google-maps');
GoogleMapsLoader.KEY = 'your-api-key';
GoogleMapsLoader.LIBRARIES = ['geometry'];

GoogleMapsLoader.load(function(google) {
  var options = { google: google };
  var filtered = Distance.filter(data, options); // data is an array of coordinates
  var points = Distance.mapToGoogle(filtered, options);
  var distance = Distance.computeDistance(points, options);
};

To compute distance on a raw dataset, without filtering, pass your raw data to mapToGoogle directly, instead of passing it through filter first.

Keywords

geolocation

FAQs

Package last updated on 30 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts