با تنظیم ویژگی collisionBehavior روی یکی از مقادیر زیر، میتوانید مشخص کنید که یک نشانگر در هنگام برخورد با نشانگر یا برچسب نقشه دیگری چگونه باید رفتار کند:
REQUIRED : نشانگر باید همیشه بدون توجه به برخورد نمایش داده شود.
REQUIRED_AND_HIDES_OPTIONAL : نشانگر باید همیشه بدون توجه به برخوردها نمایش داده شود. نشانگرهایی با رفتار برخورد OPTIONAL_AND_HIDES_LOWER_PRIORITY ، برچسبهای پیشفرض نقشه که با این نشانگر همپوشانی دارند، پنهان میشوند.
OPTIONAL_AND_HIDES_LOWER_PRIORITY : نشانگر فقط در صورتی باید نمایش داده شود که با دیگر نشانگرها همپوشانی نداشته باشد. اگر دو نشانگر از این نوع همپوشانی داشته باشند، نشانگر با ترتیب ترسیم بالاتر نشان داده می شود. اگر ترتیب ترسیم یکسانی داشته باشند، موردی با موقعیت صفحه عمودی پایین نشان داده می شود.
نمونه کد زیر هر یک از مقادیر رفتار برخورد را نشان می دهد. برای استفاده از این نمونه کد، دستورالعملهای موجود در راهاندازی را دنبال کنید و نقشه سه بعدی را به برنامه خود اضافه کنید تا پروژه Android Studio خود را با یک نقشه سه بعدی اولیه تنظیم کنید. سپس کد زیر را به فایل MainActivity.kt اضافه کنید:
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Configure marker collision behavior\n\nSelect platform: [Android](/maps/documentation/maps-3d/android-sdk/configure-marker-collision-behavior \"View this page for the Android platform docs.\") [iOS](/maps/documentation/maps-3d/ios-sdk/configure-marker-collision-behavior \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/3d/marker-collision \"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\nYou can specify how a marker should behave when it collides with another\nmarker or map label by setting the\n[`collisionBehavior`](/maps/documentation/maps-3d/android-sdk/reference/com/google/android/gms/maps3d/model/CollisionBehavior)\nproperty to one of the following values:\n\n- `REQUIRED`: The marker should always be displayed regardless of collisions.\n- `REQUIRED_AND_HIDES_OPTIONAL`: The marker should always be displayed regardless of collisions. Markers with `OPTIONAL_AND_HIDES_LOWER_PRIORITY` collision behavior r the default map labels that overlap with this marker will be hidden.\n- `OPTIONAL_AND_HIDES_LOWER_PRIORITY`: The marker should only be displayed if it does not overlap with other markers. If two markers of this type would overlap, the one with the higher draw order is shown. If they have the same draw order, the one with the lower vertical screenposition is shown.\n\n\nThe following code\nsample demonstrates each of the collision behavior values. 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// Marker 1: REQUIRED\ngoogleMap3D.addMarker(markerOptions {\n position = latLngAltitude {\n latitude = 52.52027645136134\n longitude = 13.408271658592406\n altitude = 0.0\n }\n label = \"Collision Behavior: REQUIRED\"\n altitudeMode = AltitudeMode.CLAMP_TO_GROUND\n isExtruded = true\n isDrawnWhenOccluded = true\n collisionBehavior = CollisionBehavior.REQUIRED\n})\n\n// Marker 2: REQUIRED_AND_HIDES_OPTIONAL\ngoogleMap3D.addMarker(markerOptions {\n position = latLngAltitude {\n latitude = 52.519605780912585\n longitude = 13.406867190588198\n altitude = 150.0\n }\n label = \"Colliding Behavior: REQUIRED_AND_HIDES_OPTIONAL\"\n altitudeMode = AltitudeMode.ABSOLUTE\n isExtruded = true\n isDrawnWhenOccluded = true\n collisionBehavior = CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL\n})\n\n// Marker 3: OPTIONAL_AND_HIDES_LOWER_PRIORITY\ngoogleMap3D.addMarker(markerOptions {\n position = latLngAltitude {\n latitude = 52.519882191069016\n longitude = 13.407410777254293\n altitude = 50.0\n }\n label = \"Colliding Behavior: OPTIONAL_AND_HIDES_LOWER_PRIORITY\"\n altitudeMode = AltitudeMode.RELATIVE_TO_GROUND\n isExtruded = true\n isDrawnWhenOccluded = true\n collisionBehavior = CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY\n})\n```"]]