From f35bd39e6067a526583ab5f892eab05245dbdfee Mon Sep 17 00:00:00 2001 From: Chris Finn Date: Wed, 5 Aug 2015 14:18:28 -0400 Subject: [PATCH] Fixed typo & added the filter units Fixed typo in nearby sort function & added the ability to specify units when filtering for nearby points. --- lib/geo.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/geo.js b/lib/geo.js index f3c6bdee..c687dded 100644 --- a/lib/geo.js +++ b/lib/geo.js @@ -15,6 +15,7 @@ exports.nearFilter = function nearFilter(where) { result = { near: ex.near, maxDistance: ex.maxDistance, + unit: ex.unit, key: key }; } @@ -31,6 +32,7 @@ exports.nearFilter = function nearFilter(where) { exports.filter = function (arr, filter) { var origin = filter.near; var max = filter.maxDistance > 0 ? filter.maxDistance : false; + var unit = filter.unit; var key = filter.key; // create distance index @@ -50,7 +52,7 @@ exports.filter = function (arr, filter) { if (typeof loc.lat !== 'number') return; if (typeof loc.lng !== 'number') return; - var d = GeoPoint.distanceBetween(origin, loc); + var d = GeoPoint.distanceBetween(origin, loc, {type: unit})); if (max && d > max) { // dont add @@ -61,7 +63,7 @@ exports.filter = function (arr, filter) { }); return result.sort(function (objA, objB) { - var a = objB[key]; + var a = objA[key]; var b = objB[key]; if (a && b) {