เพิ่มโมเดล 3 มิติลงในแผนที่

เลือกแพลตฟอร์ม Android iOS JavaScript

โมเดล 3 มิติบนแผนที่

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีเพิ่มโมเดล 3 มิติและวางตำแหน่งในอวกาศ 3 มิติโดยการเรียกใช้เมธอด addModel หากต้องการใช้ตัวอย่างโค้ดนี้ ให้ทําตามวิธีการในการตั้งค่า และเพิ่มแผนที่ 3 มิติลงในแอปเพื่อตั้งค่าโปรเจ็กต์ Android Studio ด้วยแผนที่ 3 มิติพื้นฐาน จากนั้นเพิ่มโค้ดต่อไปนี้ลงในไฟล์ 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
        }
    }
)