Android : Setting default zoom level for an area with com.google.android.gms.maps.GoogleMap -
i working on android application in show user nearby area location. unfortunately, when map data googlemaps, shows me entire world , dot on present location , need keep zooming in. tried set zoom factor upto 100, didn't change anything. there doing wrong. kindly let me know.
here code :
public class mapsactivitiyfragment extends fragmentactivity implements locationlistener { static googlemap googlemap; locationmanager locationmanager; string provider; latlng myposition; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.fragment_maps_activitiy); supportmapfragment fm = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.googlemap); googlemap = fm.getmap(); googlemap.setmylocationenabled(true); locationmanager = (locationmanager) getsystemservice(location_service); criteria criteria = new criteria(); provider = locationmanager.getbestprovider(criteria, true); location location = locationmanager.getlastknownlocation(provider); if (location != null) { circledraw(location.getlatitude(),location.getlongitude()); zoomin(location.getlatitude(), location.getlatitude()); onlocationchanged(location); } } @override protected void onresume() { super.onresume(); locationmanager.requestlocationupdates(provider, 400, 1, this); } public void circledraw(double i, double ii) { googlemap.addcircle(new circleoptions().center(new latlng(i, ii)) .radius(10000).strokecolor(color.black).strokewidth(5) .fillcolor(color.argb(50, 238, 116, 116))); } public void zoomin(double lat, double long) { cameraupdate center = cameraupdatefactory.newlatlng(new latlng(lat, long)); cameraupdate zoom = cameraupdatefactory.zoomto(15); googlemap.movecamera(center); googlemap.animatecamera(zoom); } @override public void onlocationchanged(location location) { googlemap.clear();// clean map toast.maketext(this, "location changed", toast.length_short).show(); double latitude = location.getlatitude(); double longitude = location.getlongitude(); myposition = new latlng(latitude, longitude); circledraw(latitude, longitude); zoomin(latitude, longitude); } @override public void onproviderdisabled(string arg0) { // todo auto-generated method stub } @override public void onproviderenabled(string arg0) { // todo auto-generated method stub } @override public void onstatuschanged(string arg0, int arg1, bundle arg2) { // todo auto-generated method stub } }
update
remember onlocationchanged
invoked when you're position changed. if stand still can have problem getting have lot of problems when work on emulator.
your code looks fine. set zoom in place setup map. don't set in onlocationchanged
in code set zoom in oncreate
// edit
latlng center = new latlng(location.getlatitude(), location.getlongitude()); cameraposition.builder cameraposition = new cameraposition.builder(); cameraposition.target(center); cameraposition.zoom((int)configuration.get("zoom")); map.animatecamera(cameraupdatefactory.newcameraposition(cameraposition.build()));
Comments
Post a Comment