Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

google maps - Autofilling the distance in driving miles between a specific address in one cell and another full set of addresses in a separate row?

I have my API key and I have successfully found the distance between two states in the US applying the link:

https://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=driving&language=fr-FR&key=AIzaSyDV3Oz0hw9RaQQyBucUvLVIft4ZDNFOebg

as detailed by a Google Maps Platform overview, but of course I get a whole page of information, most of which I don't need.

All I am looking to do is find the distance in driving miles between a specific address in one cell and another full set of addresses in a separate row of cells, and to autofill the results in a separate row.

I originally used this code:

function DrivingMeters(origin, destination) {
  var directions = Maps.newDirectionFinder()
  .setOrigin(origin)
  .setDestination(destination)
  .getDirections();
  return 
directions.routes[0].legs[0].distance.value;
}

function DrivingMiles(origin, destination) {
  return DrivingMeters(origin, 
    destination)/1609.34;
}

function DrivingSeconds(origin, destination) 
{
  var directions = Maps.newDirectionFinder()
  .setOrigin(origin)
  .setDestination(destination)
  .getDirections();
  return 
directions.routes[0].legs[0].duration.value;  
}

function DrivingHours(origin, destination) {
 return DrivingSeconds(origin, 
destination)/(60*60);
}

But there were many times where I had apparently invoked the command too many times in a day and I was locked out of using it until a full day was over. This is when I decided to switch to simply using the cloud platform services with a subscription for the distance matrix api. What can I do, either with or without the api, that can get me exactly what I need?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...