您可以在 3D 地圖中加入攝影機路徑動畫,為使用者提供更身歷其境的體驗。攝影機路徑動畫可以飛往或環繞地圖上的某個點。
目的地
下列程式碼範例示範如何呼叫 flyCameraTo
方法,將攝影機動畫效果套用至 3D 地圖上的特定點。如要使用這個程式碼範例,請按照「設定」和「在應用程式中加入 3D 地圖」中的操作說明,設定 Android Studio 專案的基本 3D 地圖。接著,將下列程式碼新增至 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 } )
飛越
下列程式碼範例示範如何呼叫 flyCameraAround
方法,將攝影機動畫設為繞著 3D 地圖上的特定點飛行。如要使用這個程式碼範例,請按照「設定」和「在應用程式中加入 3D 地圖」中的操作說明,在 Android Studio 專案中設定基本 3D 地圖。然後將下列程式碼新增至 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 } )