Google Directions API编码折线 [英] Google Directions API Encoded Polyline

查看:190
本文介绍了Google Directions API编码折线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我知道如何序列化Google Maps Directions API的JSON结果。

p>

我现在正在查看从各个路由步骤编码折线。



我在这里找到了一些解码器算法stackoverflow,但首先测试了Google自己的并知道结果是否与Google互动解码器的结果相符?



干杯,
丹尼斯



编辑:问题是返回的折线段,而不是编码算法。即使Google在Directions API页面上的示例响应中提供的示例细分与底层道路几何非常差。



解决方案

我很难与此同样。我设法想出的唯一解决方案是(使用很棒),就是使用Google的快速路由API。将不准确的折线的坐标发送到API,它将返回更正的坐标。



希望这有帮助。


I am trying to map routes which should match the Google Maps street network.

I know how to serialize the JSON result from the Google Maps Directions API.

I am looking now at encoding the polylines from the individual routing steps.

I have found some decoder algorithm here on stackoverflow but tested first Google's own Interactive Polyline Encoder. I would expect the encoded line to match the Google Map but it doesn't.

The screenshot shows the result of an encoded segment in the Interactive Polyline Encoder on the left and the result from a Google Maps route on the right.

The encoded polyline is "uxhuBxrc|QPA@?@?B?B@@B@D@HDFD@B@H@JBB@DBFJ"

Is it possible that the Algorithm in Google's Interactive Polyline Encoder is wrong?

Has anyone tested Jeffrey Sambells algorithm and knows whether the results match the results from Google's Interactive decoder?

Cheers, Dennis

EDIT: The problem is with the returned polyline segments and not the encoding algorithm. Even the sample segment which Google provides in the example response on the Directions API page fits very poorly with the underlying road geometry.

解决方案

I had a hard time with this as well. The only solution I managed to come up with (works great though) is to use Google's snap to road API. Send the coordinates of your inaccurate polyline to the API and it will give back the corrected coordinates.

Hope this helps.

这篇关于Google Directions API编码折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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