Google地图 - 发现较低路线的积分顺序 [英] Google Maps - Discover order of points for the lower route

查看:119
本文介绍了Google地图 - 发现较低路线的积分顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



假设我有四个点A,B,C和D,我们需要一种方法来找出使用Google Maps API的点之间的最佳路线。我将从A点开始,需要弄清楚我应该访问的最佳序列,并在地图上绘制出这个序列中最小的路线点。



从我在API文档中研究的内容很容易找到多个点之间的最低路线,但API期望点的顺序。在我的情况下,我需要API来给我返回最佳订单。



我认为的解决方案是找到所有可能的方法,然后找到所有这些方法的最短路径然后显示这条路线。但是这个解决方案的性能并不好,Google API限制了一天中可以抽取的路线数量。 解决方案

使用: {optimizeWaypoints:true}

 
您可以通过DirectionsRequest中的optimizeWaypoints:true来允许
Directions服务通过以更有效的顺序重新布置航点
来优化所提供的航线。 (这个优化是
旅行推销员问题的一个应用。)所有的路标必须是
theDirections服务的中途停留时间,以优化他们的路线。

小提琴与{optimizeWaypoints:false }

  var start =纽约纽约; 
var end =纽约纽约;
var waypts = [];
var wayptsIn = [Montreal,QBC,Toronto,ONT,Chicago,IL,Winnipeg,MB,Fargo,ND,Calgary,AB,Spokane,WA] ;

for(var i = 0; i< wayptsIn.length; i ++){
waypts.push({
location:wayptsIn [i],
stopover :true
});


var request = {
origin:start,
destination:end,
waypoints:waypts,
optimizeWaypoints:false,
travelMode:google.maps.TravelMode.DRIVING
};

与optimizeWaypoints相同的小提琴:true}

  var start =纽约,NY; 
var end =纽约纽约;
var waypts = [];
var wayptsIn = [Montreal,QBC,Toronto,ONT,Chicago,IL,Winnipeg,MB,Fargo,ND,Calgary,AB,Spokane,WA] ;
for(var i = 0; i< wayptsIn.length; i ++){
waypts.push({
location:wayptsIn [i],
stopover:true
});
}

var request = {
origin:start,
destination:end,
waypoints:waypts,
optimizeWaypoints:true,
travelMode:google.maps.TravelMode.DRIVING
};


I need a way to find out what the best route between points using the Google Maps API.

Assuming I have four points A, B, C and D, and I'll go from point A, need to figure out what the best sequence should I visit and plot the points on the map the smallest route to this sequence.

From what I researched in the API documentation, it is easy to find the lowest route between multiple points, but the API expects the order of points. In my case I need the API to return me the best order.

The solution that I thought was to find all possible ways, then find the shortest route to all of them and then show this route. But this solution will not have good performance and the Google API has limited the amount of routes that can draw in a day.

解决方案

Use: {optimizeWaypoints: true}

you may pass optimizeWaypoints: true within the DirectionsRequest to allow the
Directions service to optimize the provided route by rearranging the waypoints
in a more efficient order. (This optimization is an application of the 
Travelling Salesman Problem.) All waypoints must be stopovers for 
theDirections service to optimize their route.

fiddle with {optimizeWaypoints: false}

var start = "New York, NY";
var end = "New York, NY";
var waypts = [];
var wayptsIn = ["Montreal, QBC", "Toronto, ONT", "Chicago,IL", "Winnipeg,MB", "Fargo,ND", "Calgary,AB", "Spokane,WA"];

for (var i = 0; i < wayptsIn.length; i++) {
    waypts.push({
        location: wayptsIn[i],
        stopover: true
    });
}

var request = {
    origin: start,
    destination: end,
    waypoints: waypts,
    optimizeWaypoints: false,
    travelMode: google.maps.TravelMode.DRIVING
};

same fiddle with optimizeWaypoints: true}

var start = "New York, NY";
var end = "New York, NY";
var waypts = [];
var wayptsIn = ["Montreal, QBC", "Toronto, ONT", "Chicago,IL", "Winnipeg,MB", "Fargo,ND", "Calgary,AB", "Spokane,WA"];
for (var i = 0; i < wayptsIn.length; i++) {
    waypts.push({
        location: wayptsIn[i],
        stopover: true
    });
}

var request = {
    origin: start,
    destination: end,
    waypoints: waypts,
    optimizeWaypoints: true,
    travelMode: google.maps.TravelMode.DRIVING
};

这篇关于Google地图 - 发现较低路线的积分顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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