![](/img/trans.png)
[英](Android) Is it possible to change the shape of the polyline in google maps?
[英]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.