public/javascripts/vendor/javascripts/geolib.js
function(latlng, coords) {

			var keys = geolib.getKeys(latlng);
			var latitude = keys.latitude;
			var longitude = keys.longitude;

			var coordsArray = [];
			for(var coord in coords) {
				var d = geolib.getDistance(latlng, coords[coord]);
				coordsArray.push({key: coord, latitude: coords[coord][latitude], longitude: coords[coord][longitude], distance: d});
			}
			
			return coordsArray.sort(function(a, b) { return a.distance - b.distance; });

		}
function(latlng, coords) {

			var keys = geolib.getKeys(latlng);
			var latitude = keys.latitude;
			var longitude = keys.longitude;

			var coordsArray = [];
			for(var coord in coords) {
				var d = geolib.getDistance(latlng, coords[coord]);
				coordsArray.push({key: coord, latitude: coords[coord][latitude], longitude: coords[coord][longitude], distance: d});
			}
			
			return coordsArray.sort(function(a, b) { return a.distance - b.distance; });

		}
function ( latlng , coords ) { var keys = geolib . getKeys ( latlng ) ; var latitude = keys . latitude ; var longitude = keys . longitude ; var coordsArray = [ ] ; for ( var coord in coords ) { var d = geolib . getDistance ( latlng , coords [ coord ] ) ; coordsArray . push ( { key : coord , latitude : coords [ coord ] [ latitude ] , longitude : coords [ coord ] [ longitude ] , distance : d } ) ; } return coordsArray . sort ( function ( a , b ) { return a . distance - b . distance ; } ) ; }
Sorts an array of coords by distance from a reference coordinate

@param		object		reference coordinate e.g. {latitude: 51.5023, longitude: 7.3815}
@param		mixed		array or object with coords [{latitude: 51.5143, longitude: 7.4138}, {latitude: 123, longitude: 123}, ...]
@return		array		ordered array
Sorts an array of coords by distance from a reference coordinate