How to use the geolib.findNearest function in geolib

To help you get started, we’ve selected a few geolib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github glennjones / mani / lib / geo.js View on Github external
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
}
github shichongrui / phone-a-friend / server / models / user-file.js View on Github external
]).then(([peersLocations, location]) => {
        var result = geolib.findNearest(location, peersLocations)
        return socketIds[result.key]
      })
    }
github luqmaan / Instabus / src / js / models / VehicleCollection.js View on Github external
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;
}
github NetsBlox / NetsBlox / src / server / rpc / procedures / air-quality / air-quality.js View on Github external
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;
};
github luqmaan / Instabus / src / js / models / StopCollection.js View on Github external
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;
};

geolib

Library to provide basic geospatial operations like distance calculation, conversion of decimal coordinates to sexagesimal and vice versa, etc. This library is currently **2D**, meaning that altitude/elevation is not yet supported by any of its functions!

MIT
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis