简体   繁体   中英

Zooming Animation in Google Maps

I am learning about Google Maps API on Android and I have just learned how to do this.

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    // Add a marker in Uman and move the camera
    LatLng uman = new LatLng(48.754683, 30.216339 );
    mMap.addMarker(new MarkerOptions().position(uman).title("Home Town"));
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(uman, 10));
}

But instead of the map loading directly into the marker, I want it to load fully zoomed out, and zoom in into the marker in an animation...

Really hope that makes sense...

Do this instead of mMap.moveCamera(..)

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    // Add a marker in Uman and move the camera
    LatLng uman = new LatLng(48.754683, 30.216339 );
    mMap.addMarker(new MarkerOptions().position(uman).title("Home Town"));
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(uman, 10));
}

Try this ....

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
    // Add a marker in Uman and move the camera
    LatLng uman = new LatLng(48.754683, 30.216339 );
    mMap.addMarker(new MarkerOptions().position(uman).title("Home Town"));
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(uman, 10));
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {                       
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(uman, 16));
        }
    }, 1000);
}

for animation replace moveCamera to animateCamera

java

map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));

kotlin:

 val cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 15f)
 map.animateCamera(cameraUpdate)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM