Vous pouvez ajouter des animations de parcours de caméra à votre carte 3D pour offrir une expérience plus immersive à vos utilisateurs. Les animations de trajectoire de la caméra peuvent se déplacer vers un point de la carte ou l'entourer.
Aller à
L'exemple de code suivant montre comment animer la caméra pour voler vers un point spécifique sur une carte 3D en appelant la méthode flyCameraTo
. Pour utiliser cet exemple de code, suivez les instructions de la section Configuration et Ajouter une carte 3D à votre application pour configurer votre projet Android Studio avec une carte 3D de base. Ajoutez ensuite le code suivant au fichier MainActivity.kt
:
// Add imports and define constants import com.google.android.gms.maps3d.model.latLngAltitude const val EMPIRE_STATE_BUILDING_LATITUDE = 40.748233 const val EMPIRE_STATE_BUILDING_LONGITUDE = -73.985663 ... // Add to the onMap3DViewReady method, after the googleMap3D object has been initialized googleMap3D.flyCameraTo( flyToOptions { endCamera = camera { center = latLngAltitude { latitude = EMPIRE_STATE_BUILDING_LATITUDE longitude = EMPIRE_STATE_BUILDING_LONGITUDE altitude = 212.0 // in meters } heading = 34.0 // bearing in degrees tilt = 67.0 // relative to vertical range = 750.0 // distance away from the focal point in meters roll = 0.0 // roll relative to horizontal } durationInMillis = 2_000 } )
Voler
L'exemple de code suivant montre comment animer la caméra pour voler autour d'un point spécifique sur une carte 3D en appelant la méthode flyCameraAround
. Pour utiliser cet exemple de code, suivez les instructions de la section Configuration et Ajouter une carte 3D à votre application pour configurer votre projet Android Studio avec une carte 3D de base. Ajoutez ensuite le code suivant au fichier MainActivity.kt
:
// Add imports and define constants import com.google.android.gms.maps3d.model.latLngAltitude const val EMPIRE_STATE_BUILDING_LATITUDE = 40.748233 const val EMPIRE_STATE_BUILDING_LONGITUDE = -73.985663 ... // Add to the onMap3DViewReady method, after the googleMap3D object has been initialized googleMap3D.flyCameraAround( flyAroundOptions { center = camera { center = latLngAltitude { latitude = EMPIRE_STATE_BUILDING_LATITUDE longitude = EMPIRE_STATE_BUILDING_LONGITUDE altitude = 212.0 } heading = 34.0 tilt = 67.0 range = 750.0 roll = 0.0 } durationInMillis = 5_000 rounds = 1.0 // Number of rotations - can be fractional } )