Google Maps v2 Set Zoom Level

Sayari picture Sayari · Jun 8, 2013 · Viewed 39.3k times · Source

When I launch Google maps in Android, it shows the whole world. What do i need to change so as to set the zoom to the marker? Here are the codes. Thanks

        googlemap.getUiSettings().setZoomControlsEnabled(true);
    googlemap.getUiSettings().setMyLocationButtonEnabled(true);


    LatLng cameraLatLng = sfLatLng;
    float cameraZoom = 17;


    if(savedInstanceState != null){
        mapType = savedInstanceState.getInt("map_type", GoogleMap.MAP_TYPE_NORMAL);

        double savedLat = savedInstanceState.getDouble("lat");
        double savedLng = savedInstanceState.getDouble("lng");
        cameraLatLng = new LatLng(savedLat, savedLng);

        cameraZoom = savedInstanceState.getFloat("zoom", 30);

        googlemap.setMapType(mapType);
        googlemap.animateCamera(CameraUpdateFactory.newLatLngZoom(cameraLatLng, cameraZoom));

Answer

Mr Roshan Pawar picture Mr Roshan Pawar · Jun 8, 2013

try this---->

  map.addMarker(new MarkerOptions().position(latlng)).setVisible(true);

  // Move the camera instantly to location with a zoom of 15.
  map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 15));

  // Zoom in, animating the camera.
  map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);