【问题标题】:Can't get my Google API to connect properly for mapping project无法让我的 Google API 正确连接以进行映射项目
【发布时间】:2019-09-21 04:58:30
【问题描述】:

我需要计算大约 72,000 对邮政编码之间的谷歌地图导出距离。我在网上找到了一个谷歌表格的功能,可以做到这一点,但我当然在通过 72,000 之前就用完了电话。所以我在 google maps api 中设置了计费,现在有了一个 API 密钥和一个 ClientID。但我仍然无法让它工作。根据我在其他地方找到的内容,请参见下面的“我尝试添加这个”。

function GOOGLEMAPS(start_address,end_address,return_type) {
  // I tried adding this:  var key = "";
  // I tried adding this: var clientID = "YourClientIDHERE.apps.googleusercontent.com"
  // I tried adding this: maps.setauthentication(clientID,key);

  var mapObj = Maps.newDirectionFinder();

  mapObj.setOrigin(start_address);
  mapObj.setDestination(end_address);
  Utilities.sleep(6000);
  var directions = mapObj.getDirections();

  var getTheLeg = directions["routes"][0]["legs"][0];

  var meters = getTheLeg["distance"]["value"];

  switch(return_type){
    case "miles":
      return meters * 0.000621371;
      break;
    case "minutes":
        // get duration in seconds
        var duration = getTheLeg["duration"]["value"];
        //convert to minutes and return
        return duration / 60;
      break;
    case "hours":
        // get duration in seconds
        var duration = getTheLeg["duration"]["value"];
        //convert to hours and return
        return duration / 60 / 60;
      break;      
    case "kilometers":
      return meters / 1000;
      break;
    default:
      return "Error: Wrong Unit Type";
   }

}

【问题讨论】:

标签: google-apps-script google-maps-api-3 maps zipcode


【解决方案1】:

该功能运行良好。我在我现在的家和我童年的家之间测试了它,并获得了 1212 英里。使用谷歌地图是 1212 英里。我会说非常接近。

【讨论】:

  • 是的,我知道该功能可以正常工作,但我正在尝试让我的 API 连接正常工作,以便可以运行 72,000 次。
猜你喜欢
  • 2012-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-12
  • 1970-01-01
相关资源
最近更新 更多