Google Maps v2 Set Zoom Level

2019-04-04 02:00发布

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));

5条回答
Summer. ? 凉城
2楼-- · 2019-04-04 02:14

If you have a Place (or bounds), you could zoom to it. E.g. zoom to specific country, city or address with .newLatLngBounds() method:

map.animateCamera(CameraUpdateFactory.newLatLngBounds(place.getViewport(), 10)); // 10 is padding

Zoom level will be selected automatically. It works perfectly with location search.

查看更多
Bombasti
3楼-- · 2019-04-04 02:15

The following code may do the trick:

    function addMarker(lat, lng, info) {
    var pt = new google.maps.LatLng(lat, lng);
    bounds.extend(pt);

You can try the following too:

    var pt = new google.maps.LatLng(lat, lng);
    map.setCenter(pt);
    map.setZoom(your desired zoom);

Edit:

 map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f) );//where 14.0 is the zoom level
查看更多
冷血范
4楼-- · 2019-04-04 02:18
    private GoogleMap mMap;


   @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.setMinZoomPreference(3.0f);
        mMap.setMaxZoomPreference(5.5f);
    }
查看更多
倾城 Initia
5楼-- · 2019-04-04 02:29
mMap.animateCamera(CameraUpdateFactory.zoomTo(19));
查看更多
beautiful°
6楼-- · 2019-04-04 02:31

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);
查看更多
登录 后发表回答