如何使用谷歌方向apis或iPhone应用程序的其他apis比较两条路线 [英] How to compare two routes using google direction apis or some other apis for iPhone app

查看:133
本文介绍了如何使用谷歌方向apis或iPhone应用程序的其他apis比较两条路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较两条路线,以检查它们是否相同或不在我的iPhone应用程序中。

有一个人X想要去点A到点B,而另一个人想要去点A1到点B1。

我可以使用google的这个方向API获得A到B之间的路线。

http://maps.googleapis.com/maps/api/directions/xml?origin=指向A地址和目的地= B点address& sensor = false



我可以将A1的路由转换为B1。

但我在xmls中获得的经度和纬度不匹配(即使单个点不匹配)。所以,这里是我的问题我怎么能匹配两条路线,我想知道是否这条路线。



解决方案

如果最佳路线A1B1实际上是路线AB的子集我期望start_location和end_locations为匹配步骤共享类似的经度和纬度,但这不是指南API的要求。从A到B的最佳路径可能会通过A1和B1,但这并不意味着从A1到B1的最佳路径将分享完全相同的步骤。



什么我认为你想要做的是查看返回的路线段的折线点,看看他们是否会按正确的顺序通过A1和B1。您可以使用这个算法将已编码的折线字符串展开为纬度和经度列表。

I want to compare two routes to check if they are same or not in my iPhone app.

There is a person X who wants to go to point A to point B and another person wants to go to point A1 to point B1.

I can get a route between A to B using this direction APIs of google.

http://maps.googleapis.com/maps/api/directions/xml?origin=Point a A address&destination=Point B address&sensor=false

same way I can get route of A1 to B1.

but the latitude and longitude I am getting in xmls are not matching (even a single point is not matching). So here is my question how can I match two routes I want to know is this same route or not.

解决方案

If the optimal route A1B1 is actually a subset of the route AB I'd expect the start_location and end_locations for the matching steps to share similar longitudes and latitudes, but this isn't a requirement of the directions API. The best path from A to B might pass through A1 and B1, but that doesn't mean the best path from A1 to B1 will share the exact same steps.

What I think you want to do is look at the polyline points returned for the route segments and see if they would pass through A1 and B1 in the correct order. You can expand the encoded polyline strings into a list of latitude and longitudes using this algorithm.

这篇关于如何使用谷歌方向apis或iPhone应用程序的其他apis比较两条路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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