הוספת מודל תלת-ממדי למפה
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
בדוגמת הקוד הבאה אפשר לראות איך מוסיפים מודל תלת-ממדי וממקמים אותו במרחב תלת-ממדי באמצעות הפעלת השיטה addModel
. כדי להשתמש בדוגמת הקוד הזו, צריך לפעול לפי ההוראות שבקטעים הגדרה והוספת מפה תלת-ממדית לאפליקציה כדי להגדיר את פרויקט Android Studio עם מפה תלת-ממדית בסיסית. אחר כך מוסיפים את הקוד הבא לקובץ 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
}
}
)
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-31 (שעון UTC).
[null,null,["עדכון אחרון: 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```"]]