Reference Error: orgin is not defined (line 3).

49 views
Skip to first unread message

Ty Sanchez

unread,
May 2, 2024, 2:01:17 AM5/2/24
to Google Apps Script Community
I created a Google Sheet to track my mileage for work. I have never had a problem until recently. I created a Script, but it is now giving me an error, even though it had worked for almost a year without issues. 

I need the script to produce actual miles and not kilometers. Here is the error I am receiving "Reference Error: orgin is not defined (line 3)." Last month it was providing this error: "Service invoked too many times for one day: route. (line 5)." 


function GetMiles(origin,destination) {
  var directions = Maps.newDirectionFinder()
  .setOrigin(orgin)
  .setDestination(destination)
  .getDirections();

  //return value
  return directions.routes[0].legs[0].distance.value/1609.34;
}

Jim Willeke

unread,
May 2, 2024, 6:07:26 AM5/2/24
to Google Apps Script Community
Not sure as you do not define how this is setup but the function works.

I tested with sheet "April"
function testGetMiles() {
var row = 4;
var originColumn = 5;
var destColumn = 6;
var ss = SpreadsheetApp.getActiveSheet();
var origin = ss.getRange(row,originColumn).getValue();
var destination = ss.getRange(row,destColumn).getValue();
Logger.log(`origin: ${origin}`);
Logger.log(`destination: ${destination}`);
Logger.log(`Distance: ${GetMiles(origin,destination)}`);
}


function GetMiles(origin,destination) {
var directions = Maps.newDirectionFinder()
.setOrigin(origin)
.setDestination(destination)
.getDirections();

//return value
return directions.routes[0].legs[0].distance.value/1609.34;
}

I am guessing that the parameters for obtaining the values for origin or destination is not correct.

Edward Friedman (Eddie)

unread,
May 2, 2024, 8:18:16 AM5/2/24
to Google Apps Script Community
There is a typo in line 3. The function specifies that the variable 'origin' as a parameter, but line 3 tries to use the variable 'orgin'. (Only 1 'i') 'orgin' isn't defined anywhere, thus you're getting the error.

On Thursday, May 2, 2024 at 2:01:17 AM UTC-4 Ty Sanchez wrote:
Reply all
Reply to author
Forward
0 new messages