在Google Maps v3中处理多个路线点路线 [英] Handling multiple routes with waypoints in Google Maps v3

查看:106
本文介绍了在Google Maps v3中处理多个路线点路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望通过可拖动的航点显示多个方向,并在每次调用Route.prototype.setWayPoints()时保存与对象或数据库中的原点,目的地相关联的每个航点。



这个人正在用可拖动路标的单一路线(并将它们保存在数据库中)。

google-maps-v3 / draggable-directions / saving-draggable-directions-saving-waypoints-google-directions-google-maps-v3.htmrel =nofollow> http://vikku.info/programming/google- maps-v3 / draggable-directions / saving-draggable-directions-saving-waypoints-google-directions-google-maps-v3.htm



我想要多个路线不是一个。我搜索了很多,但找不到任何东西!



这是我试过的。




 函数Route(origin,destination){
this.origin = origin; // LatLng
this.destination = destination; // LatLng
this.way_points = null;
};

Route.prototype.drawRoute = function(){
this.dser.route({'origin':this.origin,
'destination':this.destination,
'waypoints':this.way_points,
'travelMode':google.maps.DirectionsTravelMode.DRIVING},
function(res,sts){
if(sts =='OK '){
var dren = new google.maps.DirectionsRenderer({'draggable':true});
dren.setMap(map); //全局变量'map'
dren。 setDirections(res);
}
});
};

Route.prototype.setGMap = function(map){
this.dren.setMap(map);
};

Route.prototype.setWayPoints = function(){
this.way_points = // ...我应该怎么做?
};


/ * ---主要部分--- * /

r0 =新路线(新增google.maps.LatLng(30,31),新增google.maps.LatLng(40,41));
r0.drawRoute();

//用户在浏览器上拖放路由

r0.setWayPoints(); //新添加的航点应存储在r0.way_points

r1 =新航线(新的google.maps.LatLng(50,51),新的google.maps.LatLng(60,61));
r1.drawRoute();

//用户在浏览器上拖放路由

r1.setWayPoints(); //新添加的航点应存储在r1.way_points






<任何人都可以告诉我如何实现Route.prototype.setWayPoints,以便当前googlemap上的路径中的路标可以存储在Route对象中?

解决方案我已经稍微改变了方法,并且向Route对象添加了一个 getPoints - 方法。



这个方法将返回一个由原点,航点和目标组成的数组,所以你可以轻松地将它传递给某个地方。
(数组中的每一项都是数组[lat,lng])

http://jsfiddle.net/doktormolle/fjUqK/


I want to display multiple directions with dragable waypoints and save each waypoints associating with origin, destination in object or database whenever Route.prototype.setWayPoints() is called.

This guy is doing that with single route with dragable waypoints (and saving them in database) .

http://vikku.info/programming/google-maps-v3/draggable-directions/saving-draggable-directions-saving-waypoints-google-directions-google-maps-v3.htm

I want multiple routes not one. I googled a lot but couldn't find anything!

Here's what I tried.


function Route(origin, destination){
    this.origin = origin; // LatLng
    this.destination = destination; //LatLng
    this.way_points = null;
};

Route.prototype.drawRoute = function(){
                 this.dser.route({'origin': this.origin,
                   'destination': this.destination,
                   'waypoints': this.way_points,
                   'travelMode': google.maps.DirectionsTravelMode.DRIVING},
                   function(res,sts) {
                          if(sts=='OK'){
                              var dren = new google.maps.DirectionsRenderer({ 'draggable':true }); 
                              dren.setMap(map); //global variable 'map'
                              dren.setDirections(res);
                          }   
                  });
};

Route.prototype.setGMap = function(map){
      this.dren.setMap(map);
};

Route.prototype.setWayPoints = function(){
  this.way_points =   //... what should I do?
};


/* --- main part --- */

r0 = new Route(new google.maps.LatLng( 30, 31 ), new google.maps.LatLng( 40, 41 ));
r0.drawRoute();

// User drags and drops the route on the browser

r0.setWayPoints(); // newly added waypoints should be stored in r0.way_points

r1 = new Route(new google.maps.LatLng( 50, 51 ), new google.maps.LatLng( 60, 61));
r1.drawRoute();

// User drags and drops the route on the browser

r1.setWayPoints(); // newly added waypoints should be stored in r1.way_points


Could anyone tell me how to implement Route.prototype.setWayPoints so that the waypoints in the route on current googlemap can be stored in Route object?

解决方案

I have changed the approach slightly and added a getPoints-method to the Route-object.

This method will return an array that consists of origin, waypoints and destination, so you may easy pass it somewhere. (each item of the array will be an array [lat,lng])

http://jsfiddle.net/doktormolle/fjUqK/

这篇关于在Google Maps v3中处理多个路线点路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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