server/utils.js
/**
 * extract duration matrix from the Distance Matrix Response
 * @param {Object} data.rows The Distance Matrix response body JSON
 * @returns {Array(Array(number))} The duration_in_traffic matrix
 */
extract duration matrix from the Distance Matrix Response
@param {Object} data.rows The Distance Matrix response body JSON
@returns {Array(Array(number))} The duration_in_traffic matrix
extract duration matrix from the Distance Matrix Response @param { Object } data . rows The Distance Matrix response body JSON @returns { Array ( Array ( number )) } The duration_in_traffic matrix
function extractDurationData(data) {
  return new Promise((resolve, reject) => {
    try {
      if (data.error_message != null) {
        reject(`extractDurationData():` + data.error_message);
      } else if (!data.rows === undefined || data.rows.length === undefined || data.rows.length === 0) {
        reject("extractDurationData(): missing rows object in distance matrix response");
      } else {
        let rowLen = data.rows.length;
        let colLen = data.rows[0].elements.length;
        let durationMatrix = new Array(rowLen);
        for (let i = 0; i < rowLen; i++) {
          durationMatrix[i] = new Array(colLen);
          for (let j = 0; j < colLen; j++) {
            durationMatrix[i][j] = data.rows[i].elements[j].duration_in_traffic.value;
          }
        }
        resolve(durationMatrix);
      }
    } catch (err) {
      reject(`extractDurationData(): issue with Google reponse - ${err.message}`);
    }
  });
}
function extractDurationData ( data ) { return new Promise ( ( resolve , reject ) => { try { if ( data . error_message != null ) { reject ( ` ` + data . error_message ) ; } else if ( ! data . rows === undefined || data . rows . length === undefined || data . rows . length === 0 ) { reject ( "extractDurationData(): missing rows object in distance matrix response" ) ; } else { let rowLen = data . rows . length ; let colLen = data . rows [ 0 ] . elements . length ; let durationMatrix = new Array ( rowLen ) ; for ( let i = 0 ; i < rowLen ; i ++ ) { durationMatrix [ i ] = new Array ( colLen ) ; for ( let j = 0 ; j < colLen ; j ++ ) { durationMatrix [ i ] [ j ] = data . rows [ i ] . elements [ j ] . duration_in_traffic . value ; } } resolve ( durationMatrix ) ; } } catch ( err ) { reject ( ` ${ err . message } ` ) ; } } ) ; }
extract duration matrix from the Distance Matrix Response
 @param {Object} data.rows The Distance Matrix response body JSON
 @returns {Array(Array(number))} The duration_in_traffic matrix
extract duration matrix from the Distance Matrix Response @param { Object } data . rows The Distance Matrix response body JSON @returns { Array ( Array ( number )) } The duration_in_traffic matrix