在Google Maps API v3中使用编码多段线有什么好处? [英] Is there a benefit to using Encoded Polylines with Google Maps API v3?

查看:118
本文介绍了在Google Maps API v3中使用编码多段线有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人正在处理数百个多段线,使用 https://developers.google.com/maps/documentation/utilities/polylinealgorithm?hl=sv-SE



似乎这主要用于API v2和v3本身处理大量折线?



我似乎无法找到任何基准比较。 使用 google.maps.geometry.encoding.decodePath() 解析方案 / code>在将聚合/多边形添加到Google地图时解码编码路径。我有一千多个点的路径,而不是循环遍历每个点,并创建一个LatLng添加到多边形,一个简单的解码加载视觉更快。



<另外,正如Salman指出的那样,通过减少通过Ajax传递路径的网络流量可以获得实质性收益。以Google的示例为例:

 字符
0 1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890
38.5,-120.2 | 40.7,-120.95 | 43.252,-126.453 //折线解码:40个字符
_p〜iF〜ps | U_ulLnnqC_mqNvxq` @ //折线编码:27个字符

只有3分,我们的积分减少了33%。


If one is dealing with hundreds of polylines, would there be a big performance benefit to encoding the polylines using https://developers.google.com/maps/documentation/utilities/polylinealgorithm?hl=sv-SE

It seems that this is mostly used with API v2 and v3 handles large amounts of polylines on its own fairly well?

I can't seem to find any benchmark comparisons.

解决方案

There is a substantial gain when using google.maps.geometry.encoding.decodePath() to decode encoded paths when adding a polyling/polygon to a google map. I have a couple of paths with over a thousand points, and instead of looping through each point and creating a LatLng to be added to a Polygon, a simple decode loads visually quicker.

Additionally as Salman pointed out, there can be a substantial gain by reducing network traffic for passing paths via Ajax. Take google's example:

Characters
0        1         2         3         4         5         6         7
1234567890123456789012345678901234567890123456789012345678901234567890
38.5,-120.2|40.7,-120.95|43.252,-126.453  // Polyline Decoded: 40 chars
_p~iF~ps|U_ulLnnqC_mqNvxq`@               // Polyline Encoded: 27 chars

With only 3 points we've reduced the the size of the points by 33%.

这篇关于在Google Maps API v3中使用编码多段线有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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