如果您在拨打DirectionsService时指定了provideRouteAlternatives为true,您能否告诉DirectionsRenderer要采取哪条路线? [英] Can you tell the DirectionsRenderer which route to take if you specified provideRouteAlternatives as true in your call to DirectionsService

查看:303
本文介绍了如果您在拨打DirectionsService时指定了provideRouteAlternatives为true,您能否告诉DirectionsRenderer要采取哪条路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有ResponseService的响应,响应对象中有多个路由,因为您将provideRouteAlternatives设置为true,DirectionsRenderer仅显示routes数组中的第一个路径。 p>我希望能够指定DirectionsRenderer将显示哪条路线。



我确信我可以重建一个具有单个元素arrray的响应对象,我想要的路线,但我希望已经存在的东西,因为它可能有多个路线在您的回应。



谢谢,

解决方案

设置 routeIndex DirectionsRendererOptions 对象(来自文档):


routeIndex



类型:数字

DirectionsResult对象内路径的索引。 )


(或致电 DirectionRenderer / documentation / javascript / reference#DirectionsRendererrel =nofollow noreferrer> setRouteIndex >


setRouteIndex(routeIndex:number)



返回值:无

设置DirectionsResult对象中路由的(从零开始)索引进行渲染。


相关问题: 在Google地图上显示两点之间的多条路线


$ b 注意:您需要在调用setDirections(response)之后调用DirectionsRenderer 上的setRouteIndex()。该文档并没有说明setRouteIndex()调用,但是当它提到setOptions()必须在初始化后被调用时才提及。


if you have a response from DirectionsService that has multiple routes in the response object, because you set provideRouteAlternatives to true, DirectionsRenderer just displays the first one in the routes array.

I want to be able to specify which route the DirectionsRenderer will display.

I am sure I can rebuild a response object that has a single element arrray with just has the route I want but I was hoping something already existed given it is possible to have multiple routes in your response.

thanks, Dan

解决方案

Set the routeIndex in the DirectionsRendererOptions Object (from the documentation):

routeIndex

Type: number

The index of the route within the DirectionsResult object. The default value is 0.)

(or call the setRouteIndex function on the DirectionRenderer sometime after you have created it):

setRouteIndex(routeIndex:number)

Return Value: None

Set the (zero-based) index of the route in the DirectionsResult object to render. By default, the first route in the array will be rendered.

Related question: Display multiple routes between two points on Google Maps

Note: You need to make your call to setRouteIndex() on the DirectionsRenderer after you call setDirections(response). the documentation doesn't state that for the setRouteIndex() call but alludes to it when it mentions the setOptions() have to be called after Initialization.

这篇关于如果您在拨打DirectionsService时指定了provideRouteAlternatives为true,您能否告诉DirectionsRenderer要采取哪条路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆