Google google maps v2 performance issues

I am struggling with a problem and trying to solve it weekly, but without a solution that meets my needs. My problem is that I have to add some markers (> = 6000) to my map, and after all the ideas / suggestions and research, I still encounter performance problems because adding a marker to the map in the main stream, even if the marker which he built in the background thread.

Assumption & Progress:

  • I already read: Too many markers
  • I use clustering
  • I add only visible area markers to limit the number of markers and suppress unnecessary load.
  • I already tried using Handlers and now I use Asynctask because I understand that they are a little faster (or just a placebo)
  • At the time of adding tokens to onProgressUpdate (one by one), but I already tried to send a list and add tokens to OnPostExecute (result), but the worst performance.

My code is:

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()); } 

Any suggestions for improving performance.

+6
source share

Source: https://habr.com/ru/post/986640/


All Articles