Set a marker over all other markers in Google Maps SDK iOS

懵懂的女人 提交于 2019-12-18 13:11:21

问题


I'm trying to place a marker, but when I do it, this marker is placed behind of some markers set before (and over some others as well). I want to set it over all the markers, but I didn't find any property (like z-index) to achieve this.

This is the part of the code where I set the marker that stays behind the others:

GMSMarker *marker = [[GMSMarker alloc] init];
marker.animated=YES;
marker.position = CLLocationCoordinate2DMake(lat, lon);
marker.map = mapView_;

and this is the result:

Is there any property or way to place the green marker over all blue markers? I'm using Google Maps SDK version 1.3.0.


回答1:


This is now supported via a zIndex property added to the GMSOverlay class in version 1.4.0. From the release notes:

Added a zIndex property on all overlays. Z-Indexes are calculated in two groups: GMSMarkers and all other overlays.

Just set a high zIndex on your marker to have it drawn on top of all others. As stated by the property documentation here:

Higher zIndex value overlays will be drawn on top of lower zIndex value tile layers and overlays.

The default zIndex for a marker is 0 (at least in the current SDK version - I haven't seen it documented, but it's easy to test and confirm), so if you're not setting the zIndex for most of your markers and have one that you want to place above all the others, all you need to do is:

yourGmsMarker.zIndex = 1;


来源:https://stackoverflow.com/questions/16808563/set-a-marker-over-all-other-markers-in-google-maps-sdk-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!