Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

Green marker is placed behind some blue markers and over other blue markers

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.

like image 662
jomafer Avatar asked May 29 '13 08:05

jomafer


People also ask

How do I add multiple markers to Google Maps API?

You just need this code: var marker = new google. maps. Marker({ position: new google.

How many markers can Google Maps API handle?

2048 characters in URL is just under 100 GeoCode values. So, again no more than 100 markers.


1 Answers

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;
like image 142
Mark Amery Avatar answered Sep 19 '22 14:09

Mark Amery