将 3D 模型添加到地图

请选择平台: Android iOS JavaScript

地图上的 3D 模型

以下代码示例演示了如何通过调用 addModel 方法添加 3D 模型并将其放置在 3D 空间中。如需使用此代码示例,请按照设置向应用添加 3D 地图中的说明,在 Android Studio 项目中设置基本 3D 地图。然后,将以下代码添加到 MainActivity.kt 文件中:

// Add imports and define constants
import com.google.android.gms.maps3d.model.latLngAltitude
val PLANE_URL = "https://storage.googleapis.com/gmp-maps-demos/p3d-map/assets/Airplane.glb"
val PLANE_SCALE = 0.05

// Add to the onMap3DViewReady method, after the googleMap3D object has been initialized
googleMap3D.setCamera(
   camera {
        center = latLngAltitude {
            latitude = 47.133971
            longitude = 11.333161
            altitude = 2200.0
        }
        heading = 221.0
        tilt = 65.0
        range = 1_200.0
    }
)

googleMap3D.addModel(
    modelOptions {
        id = "plane_model"
        position = latLngAltitude {
            latitude = 47.133971
            longitude = 11.333161
            altitude = 2200.0
        }
        altitudeMode = AltitudeMode.ABSOLUTE
        orientation = orientation {
            heading = 41.5
            tilt = -90.0
            roll = 0.0
        }
        url = PLANE_URL
        scale = vector3D {
            x = PLANE_SCALE
            y = PLANE_SCALE
            z = PLANE_SCALE
        }
    }
)