简体   繁体   English

为Google Matrix API Javascript指定API密钥以检索使用情况

[英]Specify API Key For Google Matrix API Javascript To Retrieve Usage

i am using google matrix API successfully to retrieve the time and distance for location a to location b. 我正在成功使用Google矩阵API来检索位置a到位置b的时间和距离。

var origins = [Task.getItem("Y") + "," + Task.getItem("X")];
            var destinations = [LAT + "," + LNG];

            var distanceMatrix = new google.maps.DistanceMatrixService();
            var distanceRequest = {
                origins: origins,
                destinations: destinations,
                travelMode: google.maps.TravelMode.DRIVING,
                unitSystem: google.maps.UnitSystem.METRIC,
                avoidHighways: false,
                avoidTolls: false
            };
            distanceMatrix.getDistanceMatrix(distanceRequest, function(response, status) {
                if (status != google.maps.DistanceMatrixStatus.OK) {
                    alert('Error was: ' + status);
                } else {
                    var origins = response.originAddresses;
                    var destinations = response.destinationAddresses;
                    //debugger;
                    if (response.rows[0].elements[0].distance != null) {
                        totalDistance = response.rows[0].elements[0].distance.value;
                        totalTime = response.rows[0].elements[0].duration.value;
                        ratioPerOneMeter = totalDistance / totalTime;
                        PRDifference = 0;

                        updateDistanceAndTime();

                    } else {
                        alert("The Distance And Time Cannot Be Calculated");
                    }
                }
            });

What I want to do is add the API key but I don't know how. 我想做的是添加API密钥,但我不知道如何做。 I did add in the API key: 我确实添加了API密钥:

<script src="http://maps.googleapis.com/maps/api/js?key={KEY}&v=3.exp">

as stated here: Using a Google Apps API key with Distance Matrix 如此处所述: 将Google Apps API密钥与距离矩阵结合使用

but I think this is just for the map and not for the matrix API. 但是我认为这仅适用于地图,而不适用于矩阵API。 Can someone inform me if this is enough. 有人可以告诉我是否足够。

The Google Maps Distance Matrix Service in the Google Maps Javascript API uses the key provided in the API include. Google Maps Javascript API中的Google Maps Distance Matrix服务使用API​​ include中提供的密钥。

<script src="http://maps.googleapis.com/maps/api/js?key={KEY}">

That usage is not tracked separately in the developer console. 在开发人员控制台中不会单独跟踪该用法。 The usage tracked under "Google Maps Distance Matrix API" is the usage of the Web Service only. “ Google Maps Distance Matrix API”下跟踪的用法仅是Web Service的用法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM