Printing multiple Markers on Android google maps -
so got code trying add markers saved in database:
@override public void onmapready(googlemap googlemap) { mmap = googlemap; // add marker in sydney , move camera control.conectar(); arraylist<sucursal> sucursales = control.getsucursales(); control.cerrar(); latlng loc; for(int x=0;x<sucursales.size();x++){ loc = new latlng(sucursales.get(x).getx(), sucursales.get(x).gety()); mmap.addmarker(new markeroptions().position(loc).title(sucursales.get(x).getnombre())); } mmap.movecamera(cameraupdatefactory.zoomto(12)); mmap.movecamera(cameraupdatefactory.newlatlng(new latlng(20.67711737527203, -103.36349487304688))); }
all db rows getting obtained correctly , cicle working, first row seems "working" because not putting on right location either.
ive tried exact code time, think im missing now.
the first thing should take care of have data needed in sucursales
variable. doing can sure of placing markers on map.
here assuming markers in viewport might not true in case should latlng bounds here.
through sure of keeping markers in viewport.
latlngbounds bounds = new latlngbounds.builder().include(source).include(destination).build(); googlemap.animatecamera(cameraupdatefactory.newlatlngbounds(bounds, 100));
in case , define before loop , update in each of iteration.
@override public void onmapready(googlemap googlemap) { mmap = googlemap; // add marker in sydney , move camera control.conectar(); arraylist<sucursal> sucursales = control.getsucursales(); control.cerrar(); latlng loc; latlngbounds bounds=new latlngbounds.builder().build(); for(int x=0;x<sucursales.size();x++){ bounds.including(new latlng(sucursales.get(x).getx(), sucursales.get(x).gety())); } for(int x=0;x<sucursales.size();x++){ loc = new latlng(sucursales.get(x).getx(), sucursales.get(x).gety()); mmap.addmarker(new markeroptions().position(loc).title(sucursales.get(x).getnombre())); } mmap.animatecamera(cameraupdatefactory.newlatlngbounds(bounds, 100)); }
this bring markers viewport.
do tell if worked , accept if have wanted.
Comments
Post a Comment