Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
limit = 1000;
}
if(!options.sort){
options.sort = {
'path': 'distance',
'reverse': false
}
}
var offset = 0;
if(options.nearby.offset){
offset = options.nearby.offset;
}
// excute free text search
if(options.nearby){
geoResults = GeoLib.findNearest(options.nearby, docs, options.nearby.offset, limit);
if(geoResults){
// reformat to result format
if(!Array.isArray(geoResults)){
geoResults = [geoResults];
}
formattedResults = [];
geoResults.forEach(function(item, i) {
formattedResults.push({'ref': item.key, 'distance': item.distance});
})
}
}
// format [{"ref":"12","distance":34.6}]
return formattedResults
}
]).then(([peersLocations, location]) => {
var result = geolib.findNearest(location, peersLocations)
return socketIds[result.key]
})
}
VehicleCollection.closest = function(lat, lng, vehicles) {
if (!lat || !lng || !vehicles || !vehicles.vehicles.length) return;
var points = vehicles.vehicles.map(function(v) { return {latitude: v.lat(), longitude: v.lon()}; }),
nearestPoint = geolib.findNearest({latitude: lat, longitude: lng}, points, 0, 1),
closest = vehicles.vehicles[parseInt(nearestPoint.key)];
return closest;
}
AirConsumer._getClosestReportingLocation = function(latitude, longitude) {
var nearest = geolib.findNearest({latitude: latitude, longitude: longitude}, reportingLocations),
city = reportingLocations[nearest.key].city,
state = reportingLocations[nearest.key].state,
zipcode = reportingLocations[nearest.key].zipcode;
logger.trace('Nearest reporting location is ' + city + ', ' + state);
return zipcode;
};
StopCollection.prototype.closest = function(lat, lng) {
if (!lat || !lng || !this.stops() || !this.stops().length) {
return;
}
var points = this.stops().map(function(s) {
return {latitude: s.lat(), longitude: s.lon()};
});
var nearestPoint = geolib.findNearest({latitude: lat, longitude: lng}, points, 0, 1);
var closest = this.stops()[parseInt(nearestPoint.key)];
return closest;
};