使用Google Directions API Android避开路线中的一些坐标 [英] Avoid some coordinates in routes using Google Directions API Android

查看:122
本文介绍了使用Google Directions API Android避开路线中的一些坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用路线API时避开一些坐标。我已阅读以下博客 https://code.google.com/p/gmaps-api-issues/issues/detail?id=214



这确保Directions API不允许,如果我想避免特定的坐标。

然后我尝试了waypoint参数(它允许我们获得包含特定路线的路线坐标)考虑相同的来源和目的地:

<1>首先获取路线而不添加航点

https://maps.googleapis.com/maps/api/directions/json?origin=25.2958001,55.436142&destination=24.914744,54.968565&alternatives=true&mode=driving&key=MYKEY

2)通过添加航点(坐标,我想避免)获取路线



https://maps.googleapis.com /maps/api/directions/json?origin=25.2958001,55.436142&destination=24.914744,54.968565&waypoints=25.244456,55.404643&alternatives=true&mode=driving&key=MYKEY



3)然后比较结果并尝试从第一步中删除由第二步组成的路线。

但是在这种情况下,1st步骤返回从同一坐标(我想避免)传递的多个结果,并且结果不包含在第二步中。



我厌倦了这个。无论如何,我需要解决这个问题。



任何人都可以帮助我解决这个问题吗?或其他一些建议或计算可以帮助我的东西吗?



谢谢,

解决方案这个问题不是很清楚,但我会试图提供一个更好的方法来处理这种情况。

因为航点是在航点参数中指定的,并且可以包含一个或多个地址,所以我建议使用名称而不是由管道(|)分隔的地理坐标。这确实会降低获得错误结果的风险。

在它的顶部,您可以将 optimize:true 作为路径参数中的第一个参数,以允许路线服务优化所提供的以更高效的顺序重新排列航点。



以下是一个示例。

  https://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA | Connawarra,SA | McLaren + Vale,SA& key = API_KEY 

更多详情请参考此官方Google文档


I want to avoid some coordinates while using directions APIs.I have read the below blog https://code.google.com/p/gmaps-api-issues/issues/detail?id=214

Which ensures that Directions API doesn't allow if I want to avoid specific coordinate.

Then I have tried with waypoint parameter (Which allow us to get routes that include specific coordinate) with considering same source and destination:

1) First get the routes without adding waypoint

https://maps.googleapis.com/maps/api/directions/json?origin=25.2958001,55.436142&destination=24.914744,54.968565&alternatives=true&mode=driving&key=MYKEY

2) Get the routes by adding waypoint (Coordinate which I want to avoid)

https://maps.googleapis.com/maps/api/directions/json?origin=25.2958001,55.436142&destination=24.914744,54.968565&waypoints=25.244456,55.404643&alternatives=true&mode=driving&key=MYKEY

3) Then compare results and try to remove routes from 1st step which consists by 2nd step.

But in this case, 1st step returns multiple result which passing from the same coordinate (which I want to avoid) and that results are not included by the 2nd step.

I'm fed up with this. And I need to solve this anyhow.

Anyone can help me with this? Or Some other suggestions or calculation which can help me with stuff?

Thanks,

解决方案

The question is not very clear, but I would try to provide a better approach to deal with such situations.

Since waypoints are specified within the waypoints parameters and can consist of one or more address, I would recommend using a name instead of the geocoordinates separated by pipe (|). This would indeed reduce the risk of getting faulty results.

On the top of it you can put optimize:true as the first argument within the waypoints parameter to allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order.

Here is an example.

https://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&key=API_KEY

For more details please refer to this official Google documentation.

这篇关于使用Google Directions API Android避开路线中的一些坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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