gpt4 book ai didi

javascript - 方向和方向面板未显示 google API

转载 作者:行者123 更新时间:2023-11-28 10:01:25 30 4
gpt4 key购买 nike

Maps API - 获取路线不起作用!

我的路线没有显示在我的 map 旁边。我已经完全遵循了 API 和许多示例,看起来我做的一切都是正确的。 (我相信方向应该主要使用“directionsService.route()”之后的三行代码显示)。我有一个网络应用程序,一旦点击底部的提交按钮,它就会生成 map 和方向。方向应该在右边, map 在左边,我的 map 工作正常,但方向甚至不会显示。可能有什么东西覆盖了方向面板,导致它不显示?

我的代码如下。请帮忙,我已经看了很长时间的代码,一切都开始看起来一样了哈哈 :)

另外,我是 Google MAPS Api 和 Stackoverflow 的新手 :)

请帮助,我和许多其他正在实现这样的网络应用程序的人将不胜感激!

提前致谢!


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Waypoints in directions</title>

<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px;
}
#panel {
position: absolute;
top: 5px;
left: 50%;
margin-left: -180px;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
}
</style>
<style>
#directions-panel {
height: 100%;
float: right;
width: 390px;
overflow: auto;
}

#map-canvas {
margin-right: 400px;
}

@media print {
#map-canvas {
height: 500px;
margin: 0;
}

#directions-panel {
float: none;
width: auto;
}
}
}
</style>

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var douglasville = new google.maps.LatLng(33.751497,-84.747714);

function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var mapOptions = {
zoom: 6,
center: douglasville
}

map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('directions-panel'));

var rendererOptions = {
map: map
}
}

function calcRoute() {
var start = "3557 doris circle douglasville, ga 30135";
var end = "421 st marlow dr. lawrenceville, ga 30044";
var waypts = [];
var checkboxArray = ["4899 Chapel Hill rd douglasville, ga 30135", "120 North avenue nw atlanta, ga 30332", "275 Riverside Pkwy SW, Austell, GA 30168"]
for (var i = 0; i < checkboxArray.length; i++) {
waypts.push({
location:checkboxArray[i],
stopover:true});
}
var request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}else{
alert("something went wrong!");
}
});
}


google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>
<body>
<div id="directions_panel"></div>
<div id="map-canvas" ></div>
<div style="margin:20px;border-width:2px;"><br>
<input type="submit" onclick="calcRoute();">
</div>
</body>
</html>

最佳答案

你在这行有问题:

directionsDisplay.setPanel(document.getElementById('directions-panel'));

您文档中的元素具有 id directions_panel,而不是 directions-panel

关于javascript - 方向和方向面板未显示 google API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24715553/

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