我的 map 上显示了几个彼此靠近甚至彼此重叠的标记。我需要始终在顶部放置一个特定的标记。我先将标记添加到 map 还是最后将标记添加到 map 都没关系,它通常最终会被放置在某些标记的后面。由于某些神秘的原因,Google Maps确定了这一点。它需要与Android V2的Google Maps一起使用。
最佳答案
Android Maps API v2的2016年6月27日发行版v9.2.0现在支持z-index-请参阅https://developers.google.com/maps/documentation/android-api/releases#june_27_2016上的公告。
因此,请确保在build.gradle
中将 map /播放服务版本设置为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):
您可以在将标记添加到 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):