نمونه کد زیر نحوه اضافه کردن یک مدل سه بعدی و قرار دادن آن در فضای سه بعدی را با فراخوانی متد addModel نشان می دهد. برای استفاده از این نمونه کد، دستورالعملهای موجود در راهاندازی را دنبال کنید و نقشه سه بعدی را به برنامه خود اضافه کنید تا پروژه Android Studio خود را با یک نقشه سه بعدی اولیه تنظیم کنید. سپس کد زیر را به فایل 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}})
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[],[],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```"]]