How to Focus at Marker in google map in android -


i want know whether can focus @ added marker in android application or not. if yes, how? or there alternative way task done.

lets have added marker using below code :

map.addmarker(new markeroptions()             .title(title)             .snippet(snippet)             .icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_blue))             .position(pos)                 ); 

how focus @ marker maximum zoom. , if add 1 more marker should adjust zooming(maximum possible zoom) in such way both marker display @ once.
trying failing @ line map.movecamera(cu);.

import java.util.arraylist; import java.util.list;  import android.content.intent; import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.view.menu;  import com.google.android.gms.maps.cameraupdate; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.googlemap.cancelablecallback; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.bitmapdescriptorfactory; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.latlngbounds; import com.google.android.gms.maps.model.marker; import com.google.android.gms.maps.model.markeroptions;  public class locateuserinmap extends fragmentactivity {     private googlemap map;     private list<marker> markers;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_locate_user_in_map);          markers = new arraylist<marker>();         intent intent = getintent();         double frndlatval = intent.getdoubleextra("frndlatval", 0);         double frndlonval = intent.getdoubleextra("frndlonval", 0);         latlng myloc = new latlng(19.115486500000000000, 72.905544299999970000);         latlng friendloc = new latlng(frndlatval, frndlonval);         map = ((supportmapfragment) getsupportfragmentmanager()                 .findfragmentbyid(r.id.google_map)).getmap();         addtomap(myloc, "my location", "from here 0m", "blue");         addtomap(friendloc, "friend location", "from here 100m", "red");         showmarkersatonce();     }      private void showmarkersatonce() {         latlngbounds.builder builder = new latlngbounds.builder();         (marker m : markers) {             builder.include(m.getposition());         }         latlngbounds bounds = builder.build();         int padding = 0; // offset edges of map in pixels         cameraupdate cu = cameraupdatefactory.newlatlngbounds(bounds, padding);         map.movecamera(cu);     /*  map.getuisettings().setscrollgesturesenabled(false);         map.animatecamera(cu,                 //cameraupdatefactory.newlatlng(new latlng(lat, lng))                  new cancelablecallback()         {              @override             public void onfinish()             {                 map.getuisettings().setscrollgesturesenabled(true);              }              @override             public void oncancel()             {                 map.getuisettings().setallgesturesenabled(true);              }         });*/       //  map.animatecamera(cameraupdatefactory.zoomby(13));     }      private void addtomap(latlng pos, string title, string snippet,             string markercolor) {         marker localmarker = null;         if (markercolor == "blue")         {             localmarker = map.addmarker(new markeroptions()                     .title(title)                     .snippet(snippet)                     .icon(bitmapdescriptorfactory                             .defaultmarker(bitmapdescriptorfactory.hue_blue))                     .position(pos));         } else if (markercolor == "red")          {             localmarker = map.addmarker(new markeroptions()                     .title(title)                     .snippet(snippet)                     .icon(bitmapdescriptorfactory                             .defaultmarker(bitmapdescriptorfactory.hue_red))                     .position(pos));         }          markers.add(localmarker);     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.locate_user_in_map, menu);         return true;     }  } 

and logcat

08-04 13:23:32.975: w/egl_emulation(764): eglsurfaceattrib not implemented 08-04 13:23:42.787: d/dalvikvm(764): gc_concurrent freed 169k, 3% free 11335k/11591k, paused 130ms+40ms, total 336ms 08-04 13:23:49.812: d/dalvikvm(764): gc_concurrent freed 273k, 3% free 11497k/11847k, paused 121ms+124ms, total 480ms 08-04 13:23:49.972: e/activitythread(764): failed find provider info com.google.settings 08-04 13:23:50.259: e/activitythread(764): failed find provider info com.google.settings 08-04 13:23:54.223: d/dalvikvm(764): gc_concurrent freed 262k, 3% free 11686k/12039k, paused 115ms+110ms, total 396ms 

you have calculate of markers. so

latlngbounds.builder builder = new latlngbounds.builder(); each (marker m : markers) {     builder.include(m.getposition()); } latlngbounds bounds = builder.build(); 

now obtain cameraupdatefactory:

int padding = 0; // offset edges of map in pixels cameraupdate cu = cameraupdatefactory.newlatlngbounds(bounds, padding); 

finally move camera on group of markers :

googlemap.movecamera(cu); 

or if want animation:

googlemap.animatecamera(cu); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -