find distance between tow city/tow point using google sheet

 


We are going to find the distance between two city or two point 

01 we provide JavaScript you should copy and paste in your google sheet 

02 then type command as mention bellow 

then you can see below result 





01 open google sheet 



open apps Script 


paste this code 

const GOOGLEMAPS_DISTANCE = (origindestinationmode) => {
  const { routes: [data] = [] } = Maps.newDirectionFinder()
    .setOrigin(origin)
    .setDestination(destination)
    .setMode(mode)
    .getDirections();

  if (!data) {
    throw new Error("No route found!");
  }

  const { legs: [{ distance: { textdistance } } = {}] = [] } = data;
  return distance;
};






then save 







=GOOGLEMAPS_DISTANCE(B4,C4,"driving")

Type this code

and drags to bottom


then will see


that's all 

thanks you 

if you have any error or issue comment us 

















Post a Comment

0 Comments