android - How to Draw Many Polylines in Google Map Efficiently? -


i learning make android app uses google map display data users. using polyline draw out "data/lines" want show on map, draw straight on google map, mmap.addpolyline(...). (i wish can post screenshot don't have @ least 10 reputation :-( ).

but having performance issues on drawing these lines on map, because consists of 500 ~ 900 lines in small area there (by zooming in). issue when app drawing these data, app hang/stop second, froze, once finished drawing, app continue work.

so question is, how can draw many polylines smoothly without having app hang/stop second when drawing on map? such user can move around map while polylines being drawn on map?

i had tried on drawing polylines on map in different thread, got error must draw on main thread (can't remember exact exception error). other that, searched on internet example this, found example overlay or itemizedoverlay things, deprecated far know. there other options doing this? can show me examples or guide me right resources? showing me code helpful.

thank you

update: forgot include code here, , here code draw polylines:

private class loaddatatask extends asynctask<void, void, void> {      @override     protected void onpreexecute() {         // show message saying app fetching data         toast.maketext(mmainactivity,                 "fetching data ...",                 toast.length_short)                 .show();     }      @override     protected void doinbackground(string... urls) {         // load read data url in background         loaddata();          readdata();          return null;     }      @override     protected void onpostexecute(void unused) {          // draw lines here         polylineoptions lineoptions = new polylineoptions()                 .add(new latlng(locations[0].getlatitude(), locations[0].getlongitude()))                 .add(new latlng(locations[1].getlatitude(), locations[1].getlongitude()))                 .color(color.green)                 .width(5f);          polyline polyline = mmap.addpolyline(lineoptions);         linelist.add(polyline);      } } 

run fetching data draw on background thread , draw line on main tread, using below code drawing 3000 lines

set<string> routenames=cordinatepojos.keyset();             arraylist=new arraylist<string>();             arraylist.addall(routenames);             iterator=routenames.iterator();             color[0]=color.blue;             color[1]=color.green;             color[2]=color.red;             color[3]=color.cyan;             conuter=0;      thread thread=new thread(new runnable() {                          @override                         public void run() {                             // todo auto-generated method stub                             while (iterator.hasnext()) {                              latlngs = cordinatepojos.get(iterator.next());                             sortlocations(latlngs, latlngs.get(0).latitude, latlngs.get(0).longitude);                             log.d("test on background======",""+latlngs.get(0)+"======"+conuter);                             final polylineoptions polylineoptions = new polylineoptions();                             polylineoptions.addall(latlngs);                             polylineoptions.width(15-i-i);                             polylineoptions.color(color[i]);                             float[] result1 = new float[3];                               android.location.location.distancebetween(latlngs.get(0).latitude,latlngs.get(0).longitude, latlngs.get(latlngs.size()-1).latitude, latlngs.get(latlngs.size()-1).longitude, result1);                             float distance1 = result1[0];                             totaldistance=totaldistance+distance1;     //                      final markeroptions markeroptions=new markeroptions().position(latlngs.get(0)).title(arraylist.get(conuter)+"==distance between road "+ distance1/1000 + " km");     //                      final markeroptions lastmarkeroptions=new markeroptions().position(latlngs.get(latlngs.size()-1)).title(arraylist.get(conuter)+"==distance between road "+distance1/1000+ " km");                              runonuithread(new runnable() {                                      @override                                     public void run() {                                         // todo auto-generated method stub                                             /*googlemap.addmarker(markeroptions);                                             googlemap.addmarker(lastmarkeroptions);*/                                             googlemap.addpolyline(polylineoptions);                                             if (i>2) {                                                                                                                                                                                                                                             i=0;                                             }                                             i++;                                      }                                 });                              if (conuter>3000) {                                 break;                             }                              conuter++;                          }    

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -