无法从Google Direction Service api获取优化路线 [英] Not able to get optimized route from Google Direction Service api

查看:158
本文介绍了无法从Google Direction Service api获取优化路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过提供航点来使用谷歌方向api来查找优化路线。下面是我已经使用
sta sta point的航点:LHR
第一个航点:Hounslow
第二个航点: harlington

I was trying to find the optimized route using google direction api by providing the waypoints.Below are the waypoints i have used statring point: LHR first waypoint: Hounslow second waypoint: harlington

当我尝试使用 http ://findthebestroute.com/RouteFinder.html 是回答,这是明显的答案和正确答案。

When I tried to find the optimized track using http://findthebestroute.com/RouteFinder.html below is the response which is the obvious answer and correct.

但是现在我想在我的应用程序中使用google提供的directionservice api执行相同的操作。我准备了上述请求,如下所示:

But now i would like to perform same in my own application using directionservice api provided by google. I have prepared the above request as following

Request Url: http://maps.googleapis.com/maps/api/directions/json
Request Method: GET
Status Code: 200
Params: {
    "origin": "LHR",
    "mode": "driving",
    "sensor": "false",
    "departure_time": "1375789483",
    "units": "metric",
    "waypoints": "optimize:true|hounslowl|harlington"
}

并且我收到了错误的回应,豪恩斯洛和哈灵顿。我不知道我提出的要求有什么问题。任何帮助都非常明显。

and i am getting the wrong response as following which suggest me LHR to Hounslow and to harlingston. I don't know what's wrong with the request i have made. Any help is strongly appreciable.

推荐答案

很抱歉回答我自己的问题。但由于我对上述情况有很大的问题,我希望这也发生在其他情况。这是为那些有同样的问题和浪费时间来找到所需的答案的人。

Sorry to answer to my own question. But since i was having great problem with the above scenario, I hope this has happened to other as well. This is for those who are having same problem and wasting time to find the desired answer.

我在寻找问题的答案近2天。最后发现,没有直接的一步法来计算结果并按照排序顺序获得路点。但是,有一种方法可以向Google发送多个优化路由请求。

I was searching for the answer to the question for almost 2 days. And finally found that there is no direct one step method to calculate the result and get the way point in sorted order. But there is way by sending multiple optimize route request to google.

在我解释这个简单的逻辑之前,我们首先找出需要设置的必要参数

Before I explain this simple logic, let's first figure out the required parameter that you need to set


  1. 来源 - 您想从哪里开始路线

  2. 目的地 - 最后一个指向路线
  3. >
  4. waypoints =起点和终点之间的点数,优化设置为true

  1. Origin - from where you want to begin the route
  2. Destination - last point to the route
  3. waypoints = points between the origin and destination with optimize set to true

现在,需要设置原点并找到最佳最终目的地以获得最佳轨道。

Now the thing is you first need to set the origin and find the best final destination to obtain the optimized track.

例如。如果您有多个路点,请说A,B,C,D。确实,在找到最佳轨道后,此顺序可能不会保持不变。所以首先我们需要确定从我们要开始的路线开始我们假设B,然后我们需要计算三条优化轨道,假设提醒其中一个点是最终目的地。含义

For eg. if you are have number of way points say A, B, C, D. It is true that this order may not remain same after we find the optimized track. So first we need to decide that from where we want to begin the route let's assume B, then we need to calculate three optimized track assuming remining one of the point is final destination. Meaning


  1. origin:B destination:A waypoints:C,D => result [d1 km,t1 minute]

  2. origin:B destination:C waypoints:A,D => result [d2 km,t2 minute]

  3. origin:B destination:D waypoints:C,A =>结果[d3 km,t3分钟]

在结果中看到我们有三种可能的轨迹,具有不同的距离值和时间。
现在您只需根据时间优化或距离优化选择您的优化轨道即可。

seeing at the result we have three possible track with different distance value and time. Now you simply can select your optimized track based on time optimization or distance optimization.

这篇关于无法从Google Direction Service api获取优化路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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