【问题标题】:Calculating the driving distance between two addresses Google API计算两个地址之间的行驶距离 Google API
【发布时间】:2020-04-25 02:21:36
【问题描述】:

这一直没有问题,直到大约一个月前它不再计算距离并显示错误消息。关于这段代码发生了什么以及如何修复它的任何想法?

function calcRoute() {
            var start = document.getElementById("start").value;
            var end = document.getElementById("end").value;
            var distanceInput = document.getElementById("distance");

            var request = {
                origin:start, 
                destination:end,
                travelMode: google.maps.DirectionsTravelMode.DRIVING
            };
            directionsService.route(request, function(response, status) {
                if (status == google.maps.DirectionsStatus.OK) {
                    directionsDisplay.setDirections(response);
                    distanceInput.value = 
                    response.routes[0].legs[0].distance.value / 1000;
                } else {
                //Show error message
                alert("Can't find road! Please try again!");
                clearRoute();
                }
            });
        } 

【问题讨论】:

    标签: javascript jquery google-places-api


    【解决方案1】:

    他们开始为此收费。您必须在以下网站注册,并开始支付费用才能使用它:

    https://developers.google.com/maps/documentation

    【讨论】:

    • 我已经有自己的 API 密钥并为服务付费,问题似乎出在代码上。
    • 明白了。就我而言,它突然停止工作,没有任何警告,他们没有让我知道它已更改为收费服务。
    【解决方案2】:

    我找到了解决方案。 我需要启用(Directions API)让它再次工作。 干杯!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-27
      • 2015-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多