Reputation: 1440
I've looked through all the existing questions on this topic and while many say there is no way of changing the z-order of markers on Google Maps (Android API v2), I was wondering how Google Maps decides the order itself.
I should specify that by 'order' I mean the order in which Marker InfoWindows are presented when a stack of coincident markers is tapped multiple times.
My requirement is not to change the order, only predict it so that I can add a snippet to the info window e.g. "1 of 2...".
From what I have observed, the order has nothing to do with the order the markers themselves are created or added to the map. Or even their content as the order seems to vary each time the map is initialised with the same content.
I'm using the MapFragment in case that makes a difference. I haven't posted code because I don't think it sheds any light on the issue. I have used Log calls to ensure that the order that the markers are added is the same every time.
Thanks for any help you can give, if the answer is simply "it is random" then I already know a more complicated way I can achieve what I want, I was just hoping to avoid the extra work.
Upvotes: 2
Views: 807
Reputation: 22232
If you mean that two markers share the same LatLng
position, then it might be random as you said. If they are very, very close to each other, it is from my observation that visible marker is the one with bigger screen position y value. Even if that value is subpixel.
Anyway you should avoid having markers on the same position and I can suggest two clustering solutions: Android Maps Extensions and Clusterkraf.
Upvotes: 2