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:
parent
fa570a9514
commit
f35bd39e60
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue