این صفحه به شما نشان می دهد که چگونه رفتار برخورد یک نشانگر را کنترل کنید.
رفتار برخورد را برای نشانگر تنظیم کنید
رفتار برخورد نحوه نمایش نشانگر در صورت برخورد (همپوشانی) با نشانگر دیگر را کنترل می کند. نحوه ایجاد نشانگرهای پیشرفته نحوه عملکرد رفتار برخورد را تعیین می کند:
نشانگرهای پیشرفته ایجاد شده با استفاده از BitmapDescriptorFactory به عنوان نشانگرهای بیت مپ شناخته می شوند. این نشانگرها توسط نقشه اصلی ترسیم می شوند.
تمام نشانگرهای پیشرفته دیگر، از جمله آنهایی که با استفاده از متد AdvancedMarkerOptions.iconView() ایجاد شدهاند، به عنوان نشانگرهای view شناخته میشوند و بر روی یک لایه بالای نقشه اصلی ترسیم میشوند.
CollisionBehavior.REQUIRED : (پیش فرض) همیشه نشانگر را بدون توجه به برخورد نمایش دهید.
CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL همیشه نشانگر را بدون توجه به تصادم نمایش دهید و هر OPTIONAL_AND_HIDES_LOWER_PRIORITY نشانگر یا برچسبی را که با نشانگر همپوشانی دارند پنهان کنید.
CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY نشانگر را فقط در صورتی نمایش دهید که با دیگر نشانگرها همپوشانی نداشته باشد.
اگر دو نشانگر بیت مپ همپوشانی داشته باشند، نشانگر با zIndex بالاتر نشان داده می شود. اگر zIndex یکسانی داشته باشند، یکی با موقعیت عمودی پایین صفحه نمایش نشان داده می شود. برای اطلاعات بیشتر درباره zIndex ، به نشانگر z-index مراجعه کنید.
اگر دو نشانگر نما همپوشانی داشته باشند، نشانگر با zIndex بالاتر نشان داده می شود. اگر zIndex یکسان داشته باشند، آخرین نشانگر ایجاد شده با هر نشانگر ایجاد شده قبل از آن همپوشانی دارد.
از آنجایی که نشانگرهای نمایش روی یک لایه بالای نشانگرهای بیت مپ ترسیم می شوند، نشانگرهای نمایش روی نشانگرهای بیت مپ همپوشانی دارند. بنابراین، باید سعی کنید از نشانگرهایی از همان نوع برای کنترل بهتر برخورد استفاده کنید.
مثال زیر تنظیم رفتار برخورد برای یک نشانگر را نشان می دهد:
کاتلین
// Collision behavior can only be changed in the AdvancedMarkerOptions object.// Changes to collision behavior after a marker has been created are not possiblevalcollisionBehavior:Int=CollisionBehavior.REQUIRED_AND_HIDES_OPTIONALvaladvancedMarkerOptions:AdvancedMarkerOptions=AdvancedMarkerOptions().position(LatLng(10.0,10.0)).collisionBehavior(collisionBehavior)valmarker:Marker=map.addMarker(advancedMarkerOptions)?:error("Failed to add marker")
جاوا
// Collision behavior can only be changed in the AdvancedMarkerOptions object.// Changes to collision behavior after a marker has been created are not possibleintcollisionBehavior=AdvancedMarkerOptions.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL;AdvancedMarkerOptionsoptions=newAdvancedMarkerOptions().position(newLatLng(10.0,10.0)).collisionBehavior(collisionBehavior);Markermarker=map.addMarker(options);
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis page explains how to manage marker collision behavior on maps using \u003ccode\u003eAdvancedMarkerOptions.collisionBehavior\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eCollision behavior dictates how markers are displayed when they overlap, with options including \u003ccode\u003eREQUIRED\u003c/code\u003e, \u003ccode\u003eREQUIRED_AND_HIDES_OPTIONAL\u003c/code\u003e, and \u003ccode\u003eOPTIONAL_AND_HIDES_LOWER_PRIORITY\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eMarker types (bitmap and view) influence collision behavior, with view markers drawn on top of bitmap markers, and zIndex playing a role in determining visibility during overlaps.\u003c/p\u003e\n"],["\u003cp\u003eFor consistent collision handling, it's recommended to use the same marker type (either all bitmap or all view) for all markers on the map.\u003c/p\u003e\n"]]],[],null,["# Collision behavior\n\nSelect platform: [Android](/maps/documentation/android-sdk/advanced-markers/collision-behavior \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/advanced-markers/collision-behavior \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/advanced-markers/collision-behavior \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nThis page shows you how to control the collision behavior for a marker.\n\nSet collision behavior for a marker\n-----------------------------------\n\n\nCollision behavior controls how a marker displays if it collides (overlaps)\nwith another marker. The way you create an advanced markers\ndetermines how collision behavior works:\n\n- Advanced markers created by using\n [`BitmapDescriptorFactory`](/android/reference/com/google/android/gms/maps/model/BitmapDescriptorFactory)\n are referred to as *bitmap* markers. These markers are drawn by the\n core map.\n\n- All other advanced markers, including those created by\n using the `AdvancedMarkerOptions.iconView()` method, are referred to as\n *view* markers and are drawn on a layer above the core map.\n\n| **Note:** For optimal collision behavior, you should create all advanced markers of the same type. That is, if you are using a view marker for one marker then you should use view markers for all of them.\n\nTo set collision behavior, set\n[`AdvancedMarkerOptions.collisionBehavior`](/android/reference/com/google/android/gms/maps/model/AdvancedMarkerOptions#collisionBehavior(int))\nto one of the following:\n\n- `CollisionBehavior.REQUIRED`: (default) Always display the marker regardless of collision.\n- `CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL` Always display the marker regardless of collision, and hide any `OPTIONAL_AND_HIDES_LOWER_PRIORITY` markers or labels that would overlap with the marker.\n- `CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY` Display the marker\n only if it does not overlap with other markers.\n\n - If two *bitmap* markers overlap, the one with the higher `zIndex` is\n shown.\n If they have the same `zIndex`, the one with the lower vertical screen\n position is shown. For more information about the `zIndex`, see [Marker\n z-index](/maps/documentation/android-sdk/marker#marker_z-index).\n\n - If two *view* markers overlap, the one with the higher `zIndex` is\n shown. If they have the same `zIndex`, the last created marker\n overlaps any markers created before it.\n\n - Because *view* markers are drawn on a layer above *bitmap* markers,\n *view* markers overlap *bitmap* markers. Therefore, you should try\n to use markers of the same type for better collision control.\n\nThe following example shows setting collision behavior for a marker: \n\n### Kotlin\n\n```kotlin\n// Collision behavior can only be changed in the AdvancedMarkerOptions object.\n// Changes to collision behavior after a marker has been created are not possible\nval collisionBehavior: Int = CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL\nval advancedMarkerOptions: AdvancedMarkerOptions = AdvancedMarkerOptions()\n .position(LatLng(10.0, 10.0))\n .collisionBehavior(collisionBehavior)\n\nval marker: Marker = map.addMarker(advancedMarkerOptions) ?: error(\"Failed to add marker\")\n\n \n```\n\n### Java\n\n```java\n// Collision behavior can only be changed in the AdvancedMarkerOptions object.\n// Changes to collision behavior after a marker has been created are not possible\nint collisionBehavior = AdvancedMarkerOptions.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL;\nAdvancedMarkerOptions options = new AdvancedMarkerOptions()\n .position(new LatLng(10.0, 10.0))\n .collisionBehavior(collisionBehavior);\n\nMarker marker = map.addMarker(options);\n\n \n```\n\n\u003cbr /\u003e"]]