android - Update and delete specific marker in Google Map -


i displaying location of buses in google map getting location bus database table on server. facing problem delete or update locations on google map since new marker being created when longitude , latitude change in bus table. how can delete , update specific marker in google map?

i appreciate help.

code:

private void gotolocation(double lat, double lng, string route_direct) {      supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager()             .findfragmentbyid(r.id.map);     mapfragment.getmapasync(this);     final float zoom = 11;     latlng ll = new latlng(lat, lng);     if (lat != 0 && lng != 0 && !route_direct.isempty()) {         markeroptions markeropt = new markeroptions().title(route_direct)                 .position(ll).visible(true);          marker marker = map.addmarker(markeropt);         marker.showinfowindow();         cameraupdate update = cameraupdatefactory.newlatlngzoom(ll, zoom);         map.movecamera(update);      }  } 

i solved in way. created hashmap markers.

sample,

hashmap<string, marker> markerlist = new hashmap<>(); markerlist.put(route_direct, yourmarker);//add marker list markerlist.get(route_direct);//get marker list 

then in update process, try code

    if(markerlist.containskey(route_direct)){         marker marker = markerlist.get(route_direct);         //update marker     }else{         //add marker or      } 

but use flow, need have unique data marker such marker id.

hope you. luck.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -