Problem with Android polygon Google Maps v2?

I am using Google maps v2 api for the Android application that I am creating, which is to draw polygons on the map. Everything works fine when the number of polygons is small, when the number is larger, the map loads slowly, and panning and zooming are very slow. I use SupportMapFragment and add polygons like this:

    for(PolygonOptions item : items) { 
            getMap().addPolygon(poly);
    }

Is there a way to improve performance for a large number of polygons?

+5
source share
2 answers

, . , , , AsyncTask, , onProgressUpdate.

private class AddZonesTask extends AsyncTask<Zone, Zone, Integer> {
  protected Integer doInBackground(Zone... zones) {
    for (Zone zone : zones) {
      Cursor cursor = provider.query( .... );
      List<Points> points = cursorToPointsMethod(cursor);
      zone.add(points);
      publishProgress(zone);
    }
  return zones.length;
  }

  protected void onProgressUpdate(Zone... zones) {
    drawBorder(zones[0]);
  }

  protected void onPostExecute(Integer result) { }
}

drawBorder .

+1

Bobbake4 . Android , addPolygon . . asynctask, , , addPolygon doInBackground, :

    private class AddPolygonToMap extends
        AsyncTask<String, Integer, ArrayList<PolygonOptions>> {

    @Override
    protected ArrayList<PolygonOptions> doInBackground(String... urls) {
        publishProgress(1);
        return drawPolygonWithPage(urls[0]);
    }

    @Override
    protected void onProgressUpdate(Integer... progress) {
        int value = progress[0] + progressBar.getProgress();
        progressBar.setProgress(value);
    }

    @Override
    protected void onPostExecute(ArrayList<PolygonOptions> result) {
        for (int i = 0; i < result.size(); i++) {
            map.addPolygon(result.get(i));
        }
    }
}

AddPolygon... ?

0

All Articles