Is there a (easy) way for Appsheet to calculate the "driving" distance between two addresses?

Is there an easy way to calculate the distance between two points (addresses)?

We use a google script to calculate the distance between addresses using google sheets.
(See Script Below)

Is there a way to have AppSheet call the script and get the distance in a cell?

  function jobdistance(start_address, end_address){
  
    /* 
    * Get Distance between 2 different address.
    * @param start_address = Address as string. Ex: "1350 SW 57th ave, miami, Florida";
    * @param end_address = Address as string. Ex:  end_address = "5880 SW 27th Street, Miami, Floirida";
    * @ CUSTOMFUCNTION
    */
    var mapObj = Maps.newDirectionFinder();
    mapObj.setOrigin(start_address);
    mapObj.setDestination(end_address);
    var directions = mapObj.getDirections();
    var meters = directions["routes"][0]["legs"][0]["distance"]["value"];
    var miles = meters * 0.00062137;
    var time = directions["routes"][0]["legs"]["value"];
    return miles
  
  } //end function jobdistance  ***
Solved Solved
0 9 1,852
1 ACCEPTED SOLUTION

My understanding is you have your cunstom function made by GAS like โ†‘

Then for instance, you have start address in A2 cell and end address B2 cell, then you push your expression into C3 cell with

=jobdistance(A3, B2)

This is basically nothing to do with Appsheet, but how to deal with Google Spreadsheet.

View solution in original post

9 REPLIES 9

Thanks for your prompt reply.

Please note that our google script uses google maps to get a โ€œdrivingโ€ distance between two addresses.

It appears the Appsheet DISTANCE() function is a little different as it seems to use the lat and long to calculate the straight line distance between two points.

Additional Questions:
1- Is there a function to get lat and long from an address in the US?
2-Is there a way in Appsheet to calculate the โ€œDrivingโ€ distance between two addresses?
2-Is there a way to call a google sheet script from within Appsheet?

This is correct.

1- Is there a function to get lat and long from an address in the US? ๏ผšNo
2-Is there a way in Appsheet to calculate the โ€œDrivingโ€ distance between two addresses? ๏ผšNo
2-Is there a way to call a google sheet script from within Appsheet? : No , only solution is you push your custom function (expression) into google spreadsheet cell to run your script to get distance you need.

T_K thank you for your prompt response and clarifications.

Will look at how to add google sheet script into the workflow.

Thanks again.

Just add your function as expression formula for the spreadsheet.

T_K

I am new at Appsheet (1 week inโ€ฆ so please excuse if this is a silly question, But)

Do you mean using the โ€œSpreadsheet formula optionโ€ under Data Validity section of the column properties? (Hope I got this description right - if not - I will try to send a pic).

Based on Appsheet documentation this is used to pass a formula like โ€œC2 = C3 + C4โ€

Questions:

1-this seems intended to calculate the value of another cell based on the value entered for the cell selected (is this correct?).
2-can we assign a โ€œspreadsheetโ€ formula like โ€œ=C3 + C4โ€ to calculate the value of the cell itself?
3-how can we pass along a function that looks like โ€œ=DISTANCE(A,B)โ€ and applied to the cell selected.

thanks in advance for your help.

My understanding is you have your cunstom function made by GAS like โ†‘

Then for instance, you have start address in A2 cell and end address B2 cell, then you push your expression into C3 cell with

=jobdistance(A3, B2)

This is basically nothing to do with Appsheet, but how to deal with Google Spreadsheet.

T_K.

Thank you for your response.

That clarify things. Will try and report back if find issues using this.

Hi, can we use this function in google doc and use it as a template to get report?

Top Labels in this Space