gpt4 book ai didi

jquery - 谷歌地图 API v3 : routeIndex Not Working?

转载 作者:行者123 更新时间:2023-12-01 04:54:44 25 4
gpt4 key购买 nike

我正在使用 Google Maps API v3,并尝试提供“显示下一条路线”按钮,用户可以在其中循环浏览所有可用路线。

我已经让它显示第一条路线,但是当我使用 DirectionsRenderer 类的routeIndex 属性时,它只返回第一条路线。

我做错了什么吗?代码粘贴在下面。我一直使用的测试路线总共有3条路线。如果我将routeIndex属性设置为1,它仍然显示数组中的第一条路线(基本上是routeIndex[0])。

function showDirections() {
// show contact buttons
$(".contact-route-button").css({display:"block"});

// add 1 to count
count++;

// If this function has been run before, clear the directions
if(count > 1){
// Clear map
directionsDisplay.setMap(null);
//Clear Route List
document.getElementById('directions').innerHTML = "";
}

// Set map to render directions
directionsDisplay = new google.maps.DirectionsRenderer({
map: map,
/*preserveViewport: true,*/
draggable: true,
routeIndex: 1
});

// Remove hidden class form text explaning driving directions
$('#drive-text').fadeIn("fast").removeClass('hidden');

// Hide paragraph under directions form
$(".section.grids-two.maximum-780.clearfix .grid.grid-2").fadeOut("fast");

// SlideToggle panel about random fact
$(".random-fact").slideDown("fast").css({display:"block"});

// Set Panel that will display driving directions
directionsDisplay.setPanel(document.getElementById('directions'));

// Get address input text
var address = document.getElementById('dir-address').value;

// Create request to send to Google starting at the address provided
var request = {
origin: address,
destination: '531 E Market Street Indianapolis, IN 46204',
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.STANDARD,
provideRouteAlternatives: true
};


// Send request and display on map and directions box
directionsService.route(request, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
totalRoutes = countRoutes(response);
}
});
}

有什么想法吗?我遵循的说明位于 Google Maps API 文档 https://developers.google.com/maps/documentation/javascript/reference#DirectionsRendererOptions

提前致谢!!

最佳答案

看来,routeIndex 仅当 directions 属性在directionsRenderer 中可用时才有效。您可以使用:

 directionsDisplay.setOptions({directions:response,routeIndex:1});

...什么将同时设置directionsrouteIndex

关于jquery - 谷歌地图 API v3 : routeIndex Not Working?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15303527/

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