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 - npm Package Compare versions

Comparing version
0.0.3
to
0.0.4
+2
-2
index.js

@@ -66,4 +66,4 @@ var sgeo = require('sgeo');

filter: defaultFilter,
mapToGoogle: getCoordinates,
computeDistance: computeDistance
map: getCoordinates,
compute: computeDistance
};
{
"name": "compute-distance",
"version": "0.0.3",
"version": "0.0.4",
"author": "Daniel Sauble",

@@ -5,0 +5,0 @@ "description": "Find the distance represented by a set of points, filter if necessary",

+12
-22
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](https://www.npmjs.com/package/google-maps), for example).
There are three methods associated with this library:
**filter(data, options)**
**filter(data)**

@@ -21,5 +19,6 @@ A filter designed to smooth abberations from a GPS trace. It discards

**mapToGoogle(data, options)**
**map(data)**
Take an array of coordinates and convert them to google.maps.LatLng objects.
Take an array of coordinates and convert them to
[sgeo](https://www.npmjs.com/package/sgeo) objects.

@@ -33,27 +32,18 @@ Each object in the array should have the following attributes set:

**computeDistance(data, options)**
**computeDistance(data)**
Take an array of `google.maps.LatLng` objects and compute the distance they
represent in meters.
Take an array of [sgeo](https://www.npmjs.com/package/sgeo) 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](https://developers.google.com/maps/documentation/javascript/).
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);
};
var filtered = Distance.filter(data); // data is an array of coordinates
var points = Distance.map(filtered);
var distance = Distance.computeDistance(points);
To compute distance on a raw dataset, without filtering, pass your raw data to
`mapToGoogle` directly, instead of passing it through `filter` first.
`map` directly, instead of passing it through `filter` first.

@@ -67,4 +67,4 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

filter: defaultFilter,
mapToGoogle: getCoordinates,
computeDistance: computeDistance
map: getCoordinates,
compute: computeDistance
};

@@ -753,7 +753,7 @@

var raw = Distance.mapToGoogle(data);
var civilized = Distance.mapToGoogle(filtered);
var raw = Distance.map(data);
var civilized = Distance.map(filtered);
var rawDistance = Distance.computeDistance(raw);
var filteredDistance = Distance.computeDistance(civilized);
var rawDistance = Distance.compute(raw);
var filteredDistance = Distance.compute(civilized);

@@ -760,0 +760,0 @@ assert.equal(rawDistance, 103.89499999999998, 'Passed!');

@@ -6,7 +6,7 @@ var Distance = require('../index');

var raw = Distance.mapToGoogle(data);
var civilized = Distance.mapToGoogle(filtered);
var raw = Distance.map(data);
var civilized = Distance.map(filtered);
var rawDistance = Distance.computeDistance(raw);
var filteredDistance = Distance.computeDistance(civilized);
var rawDistance = Distance.compute(raw);
var filteredDistance = Distance.compute(civilized);

@@ -13,0 +13,0 @@ assert.equal(rawDistance, 103.89499999999998, 'Passed!');