Mẫu mã sau đây minh hoạ cách thêm một đường nhiều đoạn và đặt đường đó vào không gian 3D bằng cách gọi phương thức addPolyline. Để sử dụng mã mẫu này, hãy làm theo hướng dẫn trong phần Thiết lập và Thêm bản đồ 3D vào ứng dụng để thiết lập dự án Android Studio bằng một bản đồ 3D cơ bản. Sau đó, hãy thêm đoạn mã sau vào tệp MainActivity.kt:
// Add importsimportcom.google.android.gms.maps3d.model.latLngAltitude...// Add to the onMap3DViewReady method, after the googleMap3D object has been initializedgoogleMap3D.setCamera(camera{center=latLngAltitude{latitude=40.029349longitude=-105.300354altitude=1833.9}heading=326.0tilt=75.0range=3757.0})internalvaltrailLocations=""" 40.0201040, -105.2976640 40.0201080, -105.2976450 40.0201640, -105.2975120 40.0202200, -105.2973740 40.0202500, -105.2972760 40.0202960, -105.2971410 40.0203080, -105.2970990 40.0203320, -105.2970070 40.0203640, -105.2969400 40.0203710, -105.2969250 40.0203770, -105.2969220 40.0203910, -105.2969130 40.0203940, -105.2969120 40.0204200, -105.2969130 40.0204630, -105.2968910 40.0205270, -105.2968280 40.0206030, -105.2967570 40.0206590, -105.2966100 40.0206990, -105.2964870""".trimIndent().split("\n").map{val(lat,lng)=it.split(",")latLngAltitude{latitude=lat.toDouble()longitude=lng.toDouble()altitude=0.0// The trail will be clamped to the ground}}valtrailPolylineOptions=polylineOptions{coordinates=trailLocationsstrokeColor=Color.REDstrokeWidth=7.0altitudeMode=AltitudeMode.CLAMP_TO_GROUNDzIndex=5drawsOccludedSegments=true}googleMap3D.addPolyline(trailPolylineOptions)
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-16 UTC."],[],[]]