modules/query/StopsTable.js
function _parseStopsByLocation(stops, lat, lon, count, distance, callback) {

  // Calc distance to/from each stop
  for ( let i = 0; i < stops.length; i++ ) {
    stops[i].setDistance(lat, lon);
  }

  // Sort by distance
  stops.sort(Stop.sortByDistance);


  // Filter the stops to return
  let rtn = [];


  // Return 'count' stops
  if ( count !== -1 ) {
    for ( let i = 0; i < count; i++ ) {
      if ( stops.length > i ) {
        rtn.push(stops[i]);
      }
    }
  }

  // No 'count' specified, add all stops
  else {
    rtn = stops;
  }


  // Filter by distance
  if ( distance !== -1 ) {
    let temp = [];
    for ( let i = 0; i < rtn.length; i++ ) {
      if ( rtn[i].distance <= distance ) {
        temp.push(rtn[i]);
      }
    }
    rtn = temp;
  }


  // Return the Stops
  return callback(null, rtn);

}
function _parseStopsByLocation(stops, lat, lon, count, distance, callback) {

  // Calc distance to/from each stop
  for ( let i = 0; i < stops.length; i++ ) {
    stops[i].setDistance(lat, lon);
  }

  // Sort by distance
  stops.sort(Stop.sortByDistance);


  // Filter the stops to return
  let rtn = [];


  // Return 'count' stops
  if ( count !== -1 ) {
    for ( let i = 0; i < count; i++ ) {
      if ( stops.length > i ) {
        rtn.push(stops[i]);
      }
    }
  }

  // No 'count' specified, add all stops
  else {
    rtn = stops;
  }


  // Filter by distance
  if ( distance !== -1 ) {
    let temp = [];
    for ( let i = 0; i < rtn.length; i++ ) {
      if ( rtn[i].distance <= distance ) {
        temp.push(rtn[i]);
      }
    }
    rtn = temp;
  }


  // Return the Stops
  return callback(null, rtn);

}
function _parseStopsByLocation ( stops , lat , lon , count , distance , callback ) { // Calc distance to/from each stop for ( let i = 0 ; i < stops . length ; i ++ ) { stops [ i ] . setDistance ( lat , lon ) ; } // Sort by distance stops . sort ( Stop . sortByDistance ) ; // Filter the stops to return let rtn = [ ] ; // Return 'count' stops if ( count !== - 1 ) { for ( let i = 0 ; i < count ; i ++ ) { if ( stops . length > i ) { rtn . push ( stops [ i ] ) ; } } } // No 'count' specified, add all stops else { rtn = stops ; } // Filter by distance if ( distance !== - 1 ) { let temp = [ ] ; for ( let i = 0 ; i < rtn . length ; i ++ ) { if ( rtn [ i ] . distance <= distance ) { temp . push ( rtn [ i ] ) ; } } rtn = temp ; } // Return the Stops return callback ( null , rtn ) ; }
Parse the Stops by the Location Information
@param {Stop[]} stops List of Stops to parse
@param {number} lat Location Latitude
@param {number} lon Location Longitude
@param {int} count Max number of stops to return (-1 for unlimited)
@param {number} distance Max distance from location (-1 for no limit)
@param {function} callback Callback function(err, stops)
@private
Parse the Stops by the Location Information