gpt4 book ai didi

javascript - 在您的 Google Map API V3 请求中将 clientId 和签名放在哪里?

转载 作者:行者123 更新时间:2023-11-30 17:14:33 25 4
gpt4 key购买 nike

我写了一段 JavaScript 代码。我想在 Google Maps API V3 的请求中使用 durationInTraffic。此功能仅适用于 Google Maps for Work 客户。

Here它说 Maps for work 客户应该在他们的请求中包含他们的 clientId 和签名。但是我到底应该把 clientId 和签名放在我的请求中的什么地方呢?下面是我的代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?"></script>

</head>
<body style="font-family: Arial; font-size: 13px; color: red;">
<form>
<input type="text" name="start" id="start" placeholder="Start"> --> <input type="text" name="ziel" id="ziel" placeholder="Ziel"><br>
<br>
<input type="text" name="stunde" id="stunde" placeholder="Stunde">:
<input type="text" name="minute" id="minute" placeholder="Minute">
<br>
<input type="text" name="tag" id="tag" placeholder="Tag">-
<input type="text" name="monat" id="monat" placeholder="Monat">-
<input type="text" name="jahr" id="jahr" placeholder="Jahr">

</form>
<input type="submit" value="Los!" onClick="getRoute()">

<div id="durationWithTraffic">Dauer mit Vekehr: </div>
<div id="durationWithoutTraffic">Dauer ohne Vekehr: </div>
<br>
<script type="text/javascript">
function getRoute(){
var directionsService = new google.maps.DirectionsService();

var myOptions = {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var startValue=document.getElementById('start').value;
var zielValue=document.getElementById('ziel').value;

var stundeValue=document.getElementById('stunde').value;
var minuteValue=document.getElementById('minute').value;

var tagValue=document.getElementById('tag').value;
var monatValue=document.getElementById('monat').value;
var jahrValue=document.getElementById('jahr').value;

//departure time in Epoch time
var abfahrtsZeitValue=monatValue+"/"+tagValue+"/"+jahrValue+" "+stundeValue+":"+minuteValue;

var request_withTraffic = {
origin: startValue,
destination: zielValue,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
transitOptions: {
departureTime: new Date(abfahrtsZeitValue)
},
durationInTraffic: true
};

var request_withoutTraffic = {
origin: startValue,
destination: zielValue,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
transitOptions: {
departureTime: new Date(abfahrtsZeitValue)
},
durationInTraffic: false
};

directionsService.route(request_withTraffic, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {

// Display the duration:
document.getElementById('durationWithTraffic').innerHTML="Dauer mit Vekehr: ";
document.getElementById('durationWithTraffic').innerHTML +=
response.routes[0].legs[0].duration.value + " seconds";
}
});

directionsService.route(request_withoutTraffic, function(response, status) {
if (status == google.maps.DirectionsStatus.OK)
{
document.getElementById('durationWithoutTraffic').innerHTML="Dauer ohne Verkehr: ";
document.getElementById('durationWithoutTraffic').innerHTML +=
response.routes[0].legs[0].duration.value + " seconds";
}
});
}
</script>
</body>
</html>

最佳答案

您必须在调用脚本时提供您的客户端 ID 和签名,

这是你的 map 脚本

<script src="https://maps.googleapis.com/maps/api/js?client=YOUR_CLIENT_ID&v=3.17&signature=base64signature"></script>

供引用

https://developers.google.com/maps/documentation/business/clientside/#client_id https://developers.google.com/maps/documentation/business/webservices/auth#signature_examples

关于javascript - 在您的 Google Map API V3 请求中将 clientId 和签名放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26365158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com