Добавить полилинию на карту,Добавить полилинию на карту
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Выберите платформу: Android iOS JavaScript 
В следующем примере кода показано, как добавить полилинию и разместить её в трёхмерном пространстве, вызвав метод addPolyline
. Чтобы использовать этот пример кода, следуйте инструкциям в разделах «Настройка» и «Добавление 3D-карты в приложение» , чтобы настроить проект Android Studio с простой 3D-картой. Затем добавьте следующий код в файл MainActivity.kt
:
// Add imports
import com.google.android.gms.maps3d.model.latLngAltitude
...
// Add to the onMap3DViewReady method, after the googleMap3D object has been initialized
googleMap3D.setCamera(
camera {
center = latLngAltitude {
latitude = 40.029349
longitude = -105.300354
altitude = 1833.9
}
heading = 326.0
tilt = 75.0
range = 3757.0
}
)
internal val trailLocations = """
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
}
}
val trailPolylineOptions = polylineOptions {
coordinates = trailLocations
strokeColor = Color.RED
strokeWidth = 7.0
altitudeMode = AltitudeMode.CLAMP_TO_GROUND
zIndex = 5
drawsOccludedSegments = true
}
googleMap3D.addPolyline(trailPolylineOptions)
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-08-29 UTC.
[null,null,["Последнее обновление: 2025-08-29 UTC."],[],[],null,["# Add a polyline to a map\n\nSelect platform: [Android](/maps/documentation/maps-3d/android-sdk/add-polylines \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/add-polylines \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/3d/shapes-lines \"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 polyline and position it in 3D space by calling the\n[`addPolyline`](/maps/documentation/maps-3d/android-sdk/reference/com/google/android/gms/maps3d/GoogleMap3D#addPolyline(com.google.android.gms.maps3d.model.PolylineOptions))\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\nimport com.google.android.gms.maps3d.model.latLngAltitude\n\n...\n\n// Add to the onMap3DViewReady method, after the googleMap3D object has been initialized\ngoogleMap3D.setCamera(\n camera {\n center = latLngAltitude {\n latitude = 40.029349\n longitude = -105.300354\n altitude = 1833.9\n }\n heading = 326.0\n tilt = 75.0\n range = 3757.0\n }\n)\ninternal val trailLocations = \"\"\"\n 40.0201040, -105.2976640\n 40.0201080, -105.2976450\n 40.0201640, -105.2975120\n 40.0202200, -105.2973740\n 40.0202500, -105.2972760\n 40.0202960, -105.2971410\n 40.0203080, -105.2970990\n 40.0203320, -105.2970070\n 40.0203640, -105.2969400\n 40.0203710, -105.2969250\n 40.0203770, -105.2969220\n 40.0203910, -105.2969130\n 40.0203940, -105.2969120\n 40.0204200, -105.2969130\n 40.0204630, -105.2968910\n 40.0205270, -105.2968280\n 40.0206030, -105.2967570\n 40.0206590, -105.2966100\n 40.0206990, -105.2964870\n\"\"\".trimIndent().split(\"\\n\").map {\n val (lat, lng) = it.split(\",\")\n latLngAltitude {\n latitude = lat.toDouble()\n longitude = lng.toDouble()\n altitude = 0.0 // The trail will be clamped to the ground\n }\n}\n\nval trailPolylineOptions = polylineOptions {\n coordinates = trailLocations\n strokeColor = Color.RED\n strokeWidth = 7.0\n altitudeMode = AltitudeMode.CLAMP_TO_GROUND\n zIndex = 5\n drawsOccludedSegments = true\n}\n\ngoogleMap3D.addPolyline(trailPolylineOptions)\n```"]]