gpt4 book ai didi

android - 在 Android 中更改 Maps V2 map 标记的 z-index(z-order)

转载 作者:可可西里 更新时间:2023-11-01 18:55:09 25 4
gpt4 key购买 nike

我的 map 上显示了几个标记,它们要么彼此靠近,要么彼此重叠。我需要始终在顶部放置一个特定标记。不管我是先还是最后将标记添加到 map 上,它通常最终会被放置在某些标记后面。出于某种神秘的原因,谷歌地图确定了这一点。它需要与 Google Maps for Android V2 配合使用。

最佳答案

2016 年 6 月 27 日发布的 Android Maps API v2 v9.2.0 现在支持 z-index - 请参阅 https://developers.google.com/maps/documentation/android-api/releases#june_27_2016 上的公告.

因此请确保您的 map /播放服务版本在 build.gradle 中设置为 v9.2.0 或更高版本:

compile 'com.google.android.gms:play-services-maps:9.2.0'

z-index 文档如下(来自 https://developers.google.com/maps/documentation/android-api/marker#marker_z-index ):

The z-index specifies the stack order of this marker, relative to other markers on the map. A marker with a high z-index is drawn on top of markers with lower z-indexes. The default z-index value is 0.

Markers are always drawn above tile layers and other non-marker overlays (ground overlays, polylines, polygons, and other shapes) regardless of the z-index of the other overlays. Markers are effectively considered to be in a separate z-index group compared to other overlays.

您可以在将标记添加到 map 时设置索引:

map.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title("Marker z1")
.zIndex(1.0f));

... 或在创建标记后使用 Marker.setZIndex()

有关 z-index 对点击事件的影响的更多文档如下(来自 https://developers.google.com/maps/documentation/android-api/marker#marker_click_events):

  • When a user clicks on a cluster of markers, the click event is triggered for the marker with the highest z-index.
  • At most one event is triggered per click. In other words, the click is not passed down to the markers or other overlays with lower z-index values.
  • Clicking on a cluster of markers causes subsequent clicks to cycle through the cluster, selecting each in turn. The order of the cycle first prioritises z-index, then proximity to the click point.
  • If the user clicks outside the proximity of the cluster, the API recalculates the cluster and resets the state of the click cycle so that it starts from the beginning.
  • The click event falls through marker clusters to other shapes and overlays before restarting the cycle.
  • Markers are effectively considered to be in a separate z-index group compared to other overlays or shapes (polylines, polygons, circles, and/or ground overlays), regardless of the z-index of the other overlays. If multiple markers, overlays or shapes are overlaid on top of each other, the click event is cycled through the cluster of markers first, then triggered for other clickable overlays or shapes, based on their z-index values.

关于android - 在 Android 中更改 Maps V2 map 标记的 z-index(z-order),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17672133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com