Google 地圖平台即將推出新版地圖樣式。新版地圖樣式內建全新的預設調色盤,並且提升地圖體驗、改善服務的可用性。所有地圖樣式都將於 2025 年 3 月自動更新。請參閱「
Google 地圖平台新版地圖樣式」一文,進一步瞭解適用範圍及如何提早啟用。
管理標記、標籤和搜尋點衝突
本頁說明如何管理新增至地圖的標記和預設標籤 (例如搜尋點或街道名稱) 之間的衝突。
事前準備
如要管理標記和標籤衝突,請務必使用地圖 ID。
如果您是在
精簡模式中使用地圖點陣圖圖片,會無法管理標記和標籤衝突。
指定標記優先順序
使用 Marker
.CollisionBehavior
屬性來指定標記的優先順序。
請使用下列其中一個值:
REQUIRED
:此為預設值,必須顯示與其他標記、標籤和搜尋點重疊的標記。
OPTIONAL_AND_HIDES_LOWER_PRIORITY
:表示標記可由其他必要標記取代或相互重疊,或由優先順序較高的 OPTIONAL_AND_HIDES_LOWER_PRIORITY
標記取代。使用 zIndex
來協助判斷 OPTIONAL_AND_HIDES_LOWER_PRIORITY
標記之間的相對優先順序。zIndex
值越高,表示優先順序越高。
REQUIRED_AND_HIDES_OPTIONAL
:必須在顯示標記時,隱藏與該標記重疊的任何 OPTIONAL_AND_HIDES_LOWER_PRIORITY
標記、標籤或搜尋點。標記可與其他必要標記重疊。
以下程式碼範例說明如何為新標記設定 CollisionBehavior
:
val marker = map.addMarker(
MarkerOptions()
.position(LatLng(10.0, 10.0))
.zIndex(10f) // Optional.
.collisionBehavior(Marker.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY)
)
Marker marker = map.addMarker(
new MarkerOptions()
.position(new LatLng(10, 10))
.zIndex(10) // Optional.
.collisionBehavior(Marker.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY));
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-06-06 (世界標準時間)。
[null,null,["上次更新時間:2024-06-06 (世界標準時間)。"],[[["The Beta version of the SDK used for marker collision management is deprecated; migrate to the GA release for advanced markers to control this behavior."],["Marker and label collision management requires using a map ID and is unavailable in lite mode with bitmap images."],["You can prioritize marker display using the `Marker.CollisionBehavior` property with options like `REQUIRED`, `OPTIONAL_AND_HIDES_LOWER_PRIORITY`, and `REQUIRED_AND_HIDES_OPTIONAL`."],["The `CollisionBehavior` property must be set during marker creation using `AdvancedMarkerOptions` and cannot be changed afterwards."]]],["The Beta SDK is deprecated; use the GA release of advanced markers instead. Use the Migration Tool to transition from the Beta version. To manage marker and label collisions, use a map ID, not lite mode. Set marker priority with the `CollisionBehavior` property, choosing from `REQUIRED`, `OPTIONAL_AND_HIDES_LOWER_PRIORITY`, or `REQUIRED_AND_HIDES_OPTIONAL`. Higher `zIndex` values indicate higher priority for optional markers. `CollisionBehavior` can only be set in the `AdvancedMarkerOptions` object when the marker is created.\n"]]