Prevent Repeat Calculations for Google Distance Matrix API

jeff106

New Member
Joined
Dec 2, 2016
Messages
21
I have the following script below in Google Sheets set to calculate a travel time from Start to End (2 cells in the sheet that change by row). The script works great! However, for whatever reason, the sheet in the background is calling to google multiple times a day to run the same calculation even those the start or end cells were not changed. (it is possible though if a user updates those cells at which point I do want it to recalculate). What can i do to prevent it from calling google to run the same calculation? I read tried putting in a cache but read on googles website that caching is not permitted.

function GETTIME(start,end) {
var res= UrlFetchApp.fetch("https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins="+start+"&destinations="+end+"&key=MYKEY");
var content = res.getContentText();
var json = JSON.parse(content);
var time=json.rows[0].elements[0].duration.text;
Logger.log(content);

//var dis=json.rows[0].elements[0].distance.text;
var time=json.rows[0].elements[0].duration.text; return time }
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top