我正在努力解决问题并试图解决它几周但没有满足我需求的解决方案。我的问题是我要在我的地图上添加多个标记(> = 6000)并且在所有想法/建议和调查后我仍然存在性能问题,因为在地图上添加标记即使在主线程上也是如此它是在后台线程中构建的标记。
假设&安培;进度:
我的代码:
private class MarkerTask extends AsyncTask<Positions, MarkerOptions, Void> {
Projection projection;
@Override
protected void onPreExecute() {
super.onPreExecute();
projection = mMap.getProjection();
}
@Override
protected Void doInBackground(Positions... params) {
List<Vessel> positionsList = new ArrayList<Vessel>(params[0].getList());
LatLngBounds bounds = projection.getVisibleRegion().latLngBounds;
for (int i = 0; i < positionsList.size(); i++) {
if (bounds.contains(locationLatLng) && interval.contains(DateTimeUtc)) {
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(locationLatLng);
markerOptions.title(name);
markerOptions.rotation(getHeading());
markerOptions.snippet(id);
markerOptions.anchor(Constants.MARKER_ANCHOR_CENTER, Constants.MARKER_ANCHOR_CENTER);
publishProgress(markerOptions);
positionsList.remove(i);
if (isCancelled())
break;
}
}
return null;
}
@Override
protected void onProgressUpdate(MarkerOptions... values) {
mMap.addMarker(values[0]);
mMap.setOnMarkerClickListener(onMarkerClick());
}
有关如何提高性能的任何建议吗?