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) {