Google地图方向V3:地图上的多个方向 [英] Google Maps directions V3: Multiple directions on a map

查看:116
本文介绍了Google地图方向V3:地图上的多个方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在地图的单个实例上呈现多个方向(以及它们的多段线,本质上)。在地图API的以前版本中,我做了类似于

  // directions []存储GDirections对象
// x []是从XMLHTTPResponse对象提取的元素的数组
//遍历x []中的值
GEvent.addListener(directions [i],load,function(){
var polyline = this.getPolyline();
map.addOverlay(polyline);
polyline.setStrokeStyle({opacity:0.2})
});

directions [i] .load(from:here:+ x [i] .childNodes [0] .nodeValue,{getPolyline:true});

现在有了DirectionsService和DirectionsRenderer类,我不知道做什么是最佳做法一样的东西。我是否创建DirectionsRenderer类的多个实例并让它们对主映射的实例执行setMap()?我是否创建了DirectionsServices类的多个实例。



我对javascript和函数式语言都很陌生,几乎没有尝试去理解函数式闭包,因为它们与回调有关。抱歉的格式。以及。

任何帮助将不胜感激,我会尝试澄清你可能引发的任何问题。

此链接将引导您朝正确的方向发展。


I am trying to render multiple directions(well, their Polylines, essentially) on a single instance of a map. In the prior version of the maps API, I did something like

//directions[] stores the GDirections objects
//x[] is an array of Elements extracted from an XMLHTTPResponse object
//iterating over the values in x[]
GEvent.addListener(directions[i], "load", function() {
 var polyline = this.getPolyline();
 map.addOverlay(polyline);
 polyline.setStrokeStyle({opacity:0.2})
 });

directions[i].load("from:here to:"+x[i].childNodes[0].nodeValue,{getPolyline:true});

Now that there are DirectionsService and DirectionsRenderer classes, I don't know what are the best practices for doing the same thing. Do I create multiple instances of DirectionsRenderer class and have them do a setMap() to the instance of the main map? Do I create multiple instances of the DirectionsServices class.

I am very new to javascript and functional languages in general and barely got past trying to understand functional closures as they pertain to callbacks. Apologies for the formatting as well.

Any help will be appreciated, I will try and clarify any points you may raise.

解决方案

Hey Ephraim, after researching for hours and trying different solutions I came up with this, you need to create different instance of DirectionsRenderer and (this is important!) create the DirectionsService instance INSIDE the response function. This link will guide you to the right direction.

这篇关于Google地图方向V3:地图上的多个方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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