The following code sample demonstrates how to add a 3D polygon and position
it in 3D space by calling theaddPolygonmethod. To use this code sample, follow the instructions inSetupandAdd a 3D map to your appto set up your Android Studio project with a basic 3D map. Then, add the following code to theMainActivity.ktfile:
// Add imports and define variablesimportcom.google.android.gms.maps3d.model.LatLngAltitudeimportcom.google.android.gms.maps3d.model.polygonOptionsvalzooOutline="""39.7508987, -104.956538139.7502883, -104.956548939.7501976, -104.956355739.7501481, -104.95559439.7499171, -104.955304339.7495872, -104.955164839.7492407, -104.95496139.7489685, -104.954885939.7484488, -104.954896639.7481189, -104.954885939.7479539, -104.954767939.7479209, -104.954456739.7476487, -104.953534139.7475085, -104.952579239.7474095, -104.951924739.747525, -104.951377639.7476734, -104.951184439.7478137, -104.950626539.7477559, -104.949639539.7477477, -104.948620339.7478467, -104.947579639.7482344, -104.946581839.7486138, -104.945787839.7491005, -104.945487439.7495789, -104.94593839.7500491, -104.946699839.7503213, -104.947461539.7505358, -104.948695439.7505111, -104.95064839.7511215, -104.950658739.7511173, -104.952718739.7511091, -104.954644539.7508987, -104.9565381""".trimIndent().split("\n").map{line->line.split(",").map{it.trim().toDouble()}}.map{coords->latLngAltitude{latitude=coords[0]longitude=coords[1]altitude=0.0}}valzooPolygonOptions=polygonOptions{outerCoordinates=zooOutlinefillColor=Color.argb(70,255,255,0)strokeColor=Color.GREENstrokeWidth=3.0altitudeMode=AltitudeMode.CLAMP_TO_GROUND}valzooPolygon=googleMap3D.addPolygon(zooPolygonOptions)...// Add to the onMap3DViewReady method, after the googleMap3D object has been initializedgoogleMap3D.setCamera(camera{center=latLngAltitude{latitude=39.748477longitude=-104.947575altitude=1610.0}heading=290.0tilt=47.0range=2251.0})
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Add a polygon to a map\n\nSelect platform: [Android](/maps/documentation/maps-3d/android-sdk/add-polygons \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/add-polygons \"View this page for the iOS 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\nThe following code sample demonstrates how to add a 3D polygon and position\nit in 3D space by calling the\n[`addPolygon`](/maps/documentation/maps-3d/android-sdk/reference/com/google/android/gms/maps3d/GoogleMap3D#addPolygon(com.google.android.gms.maps3d.model.PolygonOptions))\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)\nto set up 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 variables\nimport com.google.android.gms.maps3d.model.LatLngAltitude\nimport com.google.android.gms.maps3d.model.polygonOptions\n\nval zooOutline = \"\"\"\n 39.7508987, -104.9565381\n 39.7502883, -104.9565489\n 39.7501976, -104.9563557\n 39.7501481, -104.955594\n 39.7499171, -104.9553043\n 39.7495872, -104.9551648\n 39.7492407, -104.954961\n 39.7489685, -104.9548859\n 39.7484488, -104.9548966\n 39.7481189, -104.9548859\n 39.7479539, -104.9547679\n 39.7479209, -104.9544567\n 39.7476487, -104.9535341\n 39.7475085, -104.9525792\n 39.7474095, -104.9519247\n 39.747525, -104.9513776\n 39.7476734, -104.9511844\n 39.7478137, -104.9506265\n 39.7477559, -104.9496395\n 39.7477477, -104.9486203\n 39.7478467, -104.9475796\n 39.7482344, -104.9465818\n 39.7486138, -104.9457878\n 39.7491005, -104.9454874\n 39.7495789, -104.945938\n 39.7500491, -104.9466998\n 39.7503213, -104.9474615\n 39.7505358, -104.9486954\n 39.7505111, -104.950648\n 39.7511215, -104.9506587\n 39.7511173, -104.9527187\n 39.7511091, -104.9546445\n 39.7508987, -104.9565381\"\"\".trimIndent()\n .split(\"\\n\")\n .map { line -\u003e line.split(\",\").map { it.trim().toDouble() } }\n .map { coords -\u003e\n latLngAltitude {\n latitude = coords[0]\n longitude = coords[1]\n altitude = 0.0\n }\n }\n\nval zooPolygonOptions = polygonOptions {\n outerCoordinates = zooOutline\n fillColor = Color.argb(70, 255, 255, 0)\n strokeColor = Color.GREEN\n strokeWidth = 3.0\n altitudeMode = AltitudeMode.CLAMP_TO_GROUND\n}\n\nval zooPolygon = googleMap3D.addPolygon(zooPolygonOptions)\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 = 39.748477\n longitude = -104.947575\n altitude = 1610.0\n }\n heading = 290.0\n tilt = 47.0\n range = 2251.0\n }\n)\n```"]]