How can i access all marker on my GoogleMap-Object (android maps v2) and set them (in)visible? -


i trying implement actionbar-button on usage sets markers on googlemap-object visible or invisible. problem don't know how can reference markers once have been created , shown on map. im looking solution stash marker-objects array, can access in other parts of code aswell. approach reasonable?

here thinking of:

 private marker[] mmarkerarray = null;  (int = 0; < mainactivity.customers.size(); i++) {       latlng location = new latlng(mdata.lat, mdata.lng);       marker marker = mmap.addmarker(new markeroptions().position(location)                           .title(mdata.title)                           .snippet(mdata.snippet));      mmarkerarray.add(marker);                          } 

and set markers invisible on within method:

for (int = 0;  < mmarkerarray.length;; i++) {     mmarkerarray[i].setvisible(false); } 

it refuses add markers marker[]-array. how can achieve it?

mmarkerarray.add(marker) doesnt work

i figured out answer regards customerlist having customers without coordinates --> (0,0;0,0). inspired this blog.

initialize arraylist:

private arraylist<marker> mmarkerarray = new arraylist<marker>(); 

add marker map , mmarkerarray:

for (int = 0; < mainactivity.customers.size(); i++) {         customer customer = mainactivity.customers.get(i);         if (customer.getlon() != 0.0) {             if (!customer.isprospect()) {                 data mdata= new data(customer.getlat(),customer.getlon(),customer.getname(),                         customer.getort());                  latlng location = new latlng(mdata.lat, mdata.lng);                  marker marker = mmap.addmarker(new markeroptions().position(location)                           .title(mdata.title)                           .snippet(mdata.snippet));                  mmarkerarray.add(marker);  }}}  

set markers not-visible

for (marker marker : mmarkerarray) {     marker.setvisible(false);     //marker.remove(); <-- works too! } 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -