google maps - ActionBar progress spinner while Adding 1000's Markers to android Googlemap -


i have android application can add 1000's of markers extended googlemap using android maps extensions. use

requestwindowfeature(window.feature_indeterminate_progress); 

while markers being added map takes 2 - 5 seconds. problems are:

  1. i have add 1000's markers on ui thread.
  2. the indeterminate spinner running on ui thread "sticks" while map markers being added.

how run indeterminate spinner in own thread isn't affected 1000's of markers being added extended map? extended map settings using these:

final fragmentmanager fm = getsupportfragmentmanager(); final supportmapfragment f = (supportmapfragment) fm.findfragmentbyid(r.id.map); mgooglemap = f.getextendedmap(); final clusteringsettings settings = new clusteringsettings(); settings.icondataprovider(new towericondataprovider(getresources())); settings.addmarkersdynamically(true); mgooglemap.setclustering(settings); 

update
discovered root cause of addmarker()
performance issue; every timer added marker googlemap calling

.icon(bitmapdescriptorfactory.fromresource(r.drawable.my_drawable))

customise marker icon
once amended code perform outside addmarker loop, achieved desired response time.
maciejgórski pushing me @ own code.

if progress spinner in actionbar similar progressdialog, yes has run in own thread work. luckily, asynctask makes easy. improvement suggest doing heavy lifting in background thread. start doing of database lookups , such in asynctask. can still add markers on ui thread, of data crunching done on background thread. onpreexeecute(), onprogressupdate(), , onpostexecute() execute on ui thread, it's safe ui operations there. check out snippet:

private class setmarkerstask extends asynctask<void, marker, void>  {      protected void onpreexecute()       {          // turn progress spinner on          setprogressbarindeterminatevisibility(false);      }       protected void doinbackground(void... params)       {          // not run on ui thread          // long-running operation here; create marker          publishprogress(mymarker);      }       protected void onprogressupdate(marker... params)       {          // add newly-created marker map          addmarker(params[0]);      }       protected void onpostexecute(void result)       {          // turn off progress spinner          setprogressbarindeterminatevisibility(false);      }  } 

this isn't need, should give idea of how structure code using progress spinner inside actionbar.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -