Fixed typo & added the filter units

Fixed typo in nearby sort function & added the ability to specify units when filtering for nearby points.
This commit is contained in:
Chris Finn 2015-08-05 14:18:28 -04:00
parent fa570a9514
commit f35bd39e60
1 changed files with 4 additions and 2 deletions

View File

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