Adding polylines in asynctask android

后端 未结 2 1090
再見小時候
再見小時候 2020-12-18 16:47

i\'m having performance issues adding polylines and thought that maybe it\'ll be possible to add them in a separate class extending AsyncTask. However as i learned that UI e

2条回答
  •  醉话见心
    2020-12-18 16:53

    I solved this issue in a way that i did not add every polyline map separately but whole polyline. For example, before i had my location about 4km away from destination and it had 280 polylines between. On every onLocationChange these polylines were drawn one-by-one to map. Now they're all added at once - AsyncTask will create polylines in the background and in the post-execute they will be added.

    @Override
    protected Object doInBackground(Object[] params) {
        PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
        for (int z = 0; z < polyline.size(); z++) {
            LatLng point = polyline.get(z);
            options.add(point);
        }
        return options;
    }
    
    protected void onPostExecute(Object result) {
        Polyline line = mMap.addPolyline((PolylineOptions) result);
    }
    

提交回复
热议问题