performance - Android Google Maps API V2 gets slower each time it loads again -


i have fragment in app has mapfragment inside. when load fragment start read 2000 marker data server , after reading them loop through each marker , add map. @ first takes 4 seconds map show these 2000 markers. each time after loading map again ( changing orientation or changing drawermenu item , backing map again ) takes more , more load markers. example after 8 times changing orientation, takes 40 seconds map load same 2000 markers !

here how initialize map :

        googlemap = ((mapfragment) getfragmentmanager().findfragmentbyid(r.id.map)).getmap();         cameraposition cameraposition = new cameraposition.builder().target( new latlng(50.941303, 6.958166)).zoom(10).build();         googlemap.movecamera(cameraupdatefactory.newcameraposition(cameraposition));          // check if map created or not         if (googlemap == null) {             toast.maketext(getactivity().getapplicationcontext(),                     "sorry! unable create maps", toast.length_short)                     .show();         } 

and here add markers map :

    (int = 0; i<mapvehicles.size(); i++)     {         // latitude , longitude         double latitude = mapvehicles.get(i).latitude;         double longitude = mapvehicles.get(i).longitude;          // create marker         markeroptions marker = new markeroptions().position(new latlng(latitude, longitude))                 .title(mapvehicles.get(i).linetripidentification).snippet(destinationshort + ": " + mapvehicles.get(i).destination);          // changing marker icon         marker.icon(bitmapdescriptorfactory.fromresource(r.drawable.vehicleannotation));          // adding marker                     vehiclemarkers.put(googlemap.addmarker(marker), mapvehicles.get(i));       } 

i used following in oncreateview of fragment has mapfragment :

this.setretaininstance(true); 

any appreciated :)

instead of removing , adding markers again , again should change position of each marker setposition (latlng latlng).


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -