Передача значения таблицы Google из сценария Служб Google в HTML возвращает неопределенное значение - PullRequest
0 голосов
/ 01 мая 2020

У меня проблемы с передачей значения из таблицы Google в функцию Javascript в HTML.

code.gs

function getSiteCoords()
{
     var emailA = Session.getActiveUser().getEmail();
  var employeesheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Employees") // data pertaining to employees

   var numRows=1;
     while(employeesheet.getRange("A"+numRows+":A"+numRows).getValue() != "") //this will count the number of rows that are filled
     {
       if(employeesheet.getRange("A"+numRows).getValue()===emailA)
       {
         let coords = employeesheet.getRange("E"+numRows).getValue();
         return coords;
       }
         numRows = numRows+1;
     }
    return "";
}

index. html

function checkPosition(position) {
  console.log("Latitude: " + position.coords.latitude +
  " Longitude: " + position.coords.longitude);

  var lat= 54.978 ;
  var long=-1.5622;
  
  var coords = google.script.run.getSiteCoords();
  console.log("Site Coords " + coords);
  let calc= Math.sqrt(Math.pow(position.coords.latitude - lat , 2) + Math.pow(position.coords.longitude - long , 2));
  console.log("calc: "+ calc);
  if(calc>0.005)
  window.location.replace("https://google.com");
}

Независимо от того, что координаты в индексе. html возвращает неопределенное значение.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...