繁体   English   中英

谷歌上的PolyLines映射android的每个位置更改,新的折线或setPoints?

[英]PolyLines on google maps android for every location change, new polyline or setPoints?

在我的应用程序中,我正在为每个位置变化绘制折线,而我正在徒步旅行。 这可能是一个8小时的背包徒步旅行,所以我可能有数万点的情节。

在我的测试中,我注意到当我放大得很近(比如说17或18)时,即使在绘制了数千行之后也能很好地工作,但是当我缩小并且地图必须渲染所有这些行时,当我的手机试图处理一切时,它变得迟钝。

我知道绘制折线的另一个选项是创建我所有点(LatLng)的集合(ArrayList)并将其传递给PolyLine的setPoints()方法,该方法绘制一条线。 这在事后审查trek时显然效果很好,但是我认为setPoints()的内部必须为每个新点循环整个集合,这些新点被添加到绘制一条线,最终可能是性能更差的因为无论旧点是否可见(在视口内)都必须这样做。

介于两者之间吗? polyline.addPoint()方法将是完美的,但我找不到类似的东西......现在作为一个止损,我只是使我的折线可见性可切换,以便我可以隐藏它们当我缩放远如我所说,当我紧密地放大时,我需要移动地图,这不是问题,因为它只需渲染一个相当小的子集。

任何想法/建议都非常感谢。

TIA

这就是我提出的解决方案。 它可能不是最优雅的,但我只是开车四十多英里在我的车里,当我缩小时,我没有任何延迟。 我也觉得通过每100点创建一个大行(大约每隔100秒,因为我的位置监听器每秒都会触发),我正在保存必须为每个位置更改循环我的latlng数组的处理。 现在我只需要在真正的艰苦跋涉中测试这个:)

// create and add new poly line to map from previos location to new location
            PolylineOptions lineOptions = new PolylineOptions()
                    .add(new LatLng(previousLocation.getLatitude(), previousLocation.getLongitude()))
                    .add(new LatLng(location.getLatitude(), location.getLongitude()))
                    .color(Color.GREEN)
                    .width(5);
            // add the polyline to the map
            Polyline polyline = map.addPolyline(lineOptions);
            // set the zindex so that the poly line stays on top of my tile overlays
            polyline.setZIndex(1000);
            // add the poly line to the array so they can all be removed if necessary
            polylines.add(polyline);
            // add the latlng from this point to the array
            allLatLngs.add(currentLocationLatLng);

            // check if the positions added is a multiple of 100, if so, redraw all of the polylines as one line (this helps with rendering the map when there are thousands of points)
            if(allLatLngs.size() % 100 == 0) {
                // first remove all of the existing polylines
                for(Polyline pline : polylines) {
                    pline.remove();
                }
                // create one new large polyline
                Polyline routeSoFar = map.addPolyline(new PolylineOptions().color(Color.GREEN).width(5));
                // draw the polyline for the route so far
                routeSoFar.setPoints(allLatLngs);
                // set the zindex so that the poly line stays on top of my tile overlays
                routeSoFar.setZIndex(1000);
                // clear the polylines array
                polylines.clear();
                // add the new poly line as the first element in the polylines array
                polylines.add(routeSoFar);
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM