furkot-directions
Advanced tools
Comparing version 1.2.1 to 1.2.2
1.2.2 / 2019-06-03 | ||
================== | ||
* check validity of result returned by Valhalla | ||
1.2.1 / 2019-04-20 | ||
@@ -3,0 +8,0 @@ ================== |
// https://github.com/valhalla/valhalla-docs | ||
const LatLon = require('geodesy/latlon-spherical'); | ||
const { pathType } = require("../../model"); | ||
@@ -69,2 +70,11 @@ const status = require('../status'); | ||
function toLatLon(p) { | ||
return new LatLon(p.lat, p.lon); | ||
} | ||
function minDistance(locations, units) { | ||
units = units === 'miles' ? util.metersInMile : util.metersInKm; | ||
return 0.9 * toLatLon(locations[0]).distanceTo(toLatLon(util.last(locations))) / units; | ||
} | ||
function getStatus(err, response) { | ||
@@ -86,5 +96,8 @@ let st = response && response.status_code; | ||
if (st === 0) { | ||
if (response.trip.legs && response.trip.legs.length) { | ||
if (response.trip.legs && response.trip.legs.length && | ||
// make sure points are not too far from roads | ||
response.trip.summary.length > minDistance(response.trip.locations, response.trip.units)) { | ||
return status.success; | ||
} | ||
delete response.trip.legs; | ||
return status.empty; | ||
@@ -91,0 +104,0 @@ } |
{ | ||
"name": "furkot-directions", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Directions service for Furkot", | ||
@@ -5,0 +5,0 @@ "author": { |
87045
1371