Add a 3D model to a map
Stay organized with collections
Save and categorize content based on your preferences.
A 3D model on a map
The following code sample
demonstrates how to add a 3D model and position it in 3D space by calling the
addModel
method. To use this code sample, follow the instructions in
Setup and
Add a 3D map to your app to set
up your Android Studio project with a basic 3D map. Then, add the following code to the
MainActivity.kt file:
// Add imports and define constants importcom.google.android.gms.maps3d.model.latLngAltitude valPLANE_URL="https://storage.googleapis.com/gmp-maps-demos/p3d-map/assets/Airplane.glb" valPLANE_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 } } )