L'exemple de code suivant montre comment ajouter un modèle 3D et le positionner dans l'espace 3D en appelant la méthode addModel. Pour utiliser cet exemple de code, suivez les instructions de 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 constantsimportcom.google.android.gms.maps3d.model.latLngAltitudevalPLANE_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 initializedgoogleMap3D.setCamera(camera{center=latLngAltitude{latitude=47.133971longitude=11.333161altitude=2200.0}heading=221.0tilt=65.0range=1_200.0})googleMap3D.addModel(modelOptions{id="plane_model"position=latLngAltitude{latitude=47.133971longitude=11.333161altitude=2200.0}altitudeMode=AltitudeMode.ABSOLUTEorientation=orientation{heading=41.5tilt=-90.0roll=0.0}url=PLANE_URLscale=vector3D{x=PLANE_SCALEy=PLANE_SCALEz=PLANE_SCALE}})
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/31 (UTC).
[null,null,["Dernière mise à jour le 2025/08/31 (UTC)."],[],[],null,["# Add a 3D model to a map\n\nSelect platform: [Android](/maps/documentation/maps-3d/android-sdk/add-3d-models \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/add-3d-models \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/3d/models \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\n| This product or feature is Experimental (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google\n| Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage descriptions](/maps/launch-stages).\n\n\nThe following code sample\ndemonstrates how to add a 3D model and position it in 3D space by calling the\n[`addModel`](/maps/documentation/maps-3d/android-sdk/reference/com/google/android/gms/maps3d/GoogleMap3D#addModel(com.google.android.gms.maps3d.model.ModelOptions))\nmethod. To use this code sample, follow the instructions in\n[Setup](/maps/documentation/maps-3d/android-sdk/setup) and\n[Add a 3D map to your app](/maps/documentation/maps-3d/android-sdk/add-a-3d-map) to set\nup your Android Studio project with a basic 3D map. Then, add the following code to the\n**`MainActivity.kt`** file:\n\n```kotlin\n// Add imports and define constants\nimport com.google.android.gms.maps3d.model.latLngAltitude\nval PLANE_URL = \"https://storage.googleapis.com/gmp-maps-demos/p3d-map/assets/Airplane.glb\"\nval PLANE_SCALE = 0.05\n\n// Add to the onMap3DViewReady method, after the googleMap3D object has been initialized\ngoogleMap3D.setCamera(\n camera {\n center = latLngAltitude {\n latitude = 47.133971\n longitude = 11.333161\n altitude = 2200.0\n }\n heading = 221.0\n tilt = 65.0\n range = 1_200.0\n }\n)\n\ngoogleMap3D.addModel(\n modelOptions {\n id = \"plane_model\"\n position = latLngAltitude {\n latitude = 47.133971\n longitude = 11.333161\n altitude = 2200.0\n }\n altitudeMode = AltitudeMode.ABSOLUTE\n orientation = orientation {\n heading = 41.5\n tilt = -90.0\n roll = 0.0\n }\n url = PLANE_URL\n scale = vector3D {\n x = PLANE_SCALE\n y = PLANE_SCALE\n z = PLANE_SCALE\n }\n }\n)\n```"]]