Android Google Maps v2 - set zoom level for myLocation

前端 未结 13 1115
孤城傲影
孤城傲影 2020-12-05 01:39

Is it possible to change the zoom level for myLocation with the new Google Maps API v2?

If you set GoogleMap.setEnableMyLocation(true);, you get a butto

相关标签:
13条回答
  • 2020-12-05 02:02

    Most of the answers above are either deprecated or the zoom works by retaining the current latitude and longitude and does not zoom to the exact location you want it to. Add the following code to your onMapReady() method.

    @Override
    public void onMapReady(GoogleMap googleMap) {
        //Set marker on the map
        googleMap.addMarker(new MarkerOptions().position(new LatLng(0.0000, 0.0000)).title("Marker"));
        //Create a CameraUpdate variable to store the intended location and zoom of the camera
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(0.0000, 0.0000), 13);
        //Animate the zoom using the animateCamera() method
        googleMap.animateCamera(cameraUpdate);
    }
    
    0 讨论(0)
  • 2020-12-05 02:08

    You can also use:

    mMap.animateCamera( CameraUpdateFactory.zoomTo( 17.0f ) );    
    

    To just change the zoom value to any desired value between minimum value=2.0 and maximum value=21.0.

    The API warns that not all locations have tiles at values at or near maximum zoom.

    See this for more information about zoom methods available in the CameraUpdateFactory.

    0 讨论(0)
  • 2020-12-05 02:09

    Here are the approximate zoom levels and what they do :

    1: World
    5: Landmass/continent
    10: City
    15: Streets
    20: Buildings
    

    so you could do something like this to zoom to street level for example (note the "15f" below is street level) :

     override fun onMapReady(googleMap: GoogleMap?) {
        googleMap?.mapType = GoogleMap.MAP_TYPE_NORMAL
        googleMap?.addMarker(MarkerOptions()
                .position(LatLng(37.4233438, -122.0728817))
                .title("cool place")
    
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE)))
    
        googleMap?.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(37.4233438, -122.0728817), 15f))
    

    note: just so you know different locations can have different max zoom levels. try to use googleMap.maxZoomLevel if you want to get the max or min zoom levels.

    0 讨论(0)
  • 2020-12-05 02:09

    Slightly different solution than HeatfanJohn's, where I change the zoom relatively to the current zoom level:

    // Zoom out just a little
    map.animateCamera(CameraUpdateFactory.zoomTo(map.getCameraPosition().zoom - 0.5f));
    
    0 讨论(0)
  • 2020-12-05 02:10
    Location locaton;
    double latitude = location.getlatitude;
    double longitude = location.getlongitude;
    

    If you want to save the zoom or get it all the time,you just need to call the following

    int zoom = mMap.getCameraPosition().zoom;
    
    //To set that just use
    
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(getlatitude(), getlongitude),zoom);
    
    0 讨论(0)
  • 2020-12-05 02:15

    with location - in new GoogleMaps SDK:

    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(chLocation,14));
    
    0 讨论(0)
提交回复
热议问题