Consider a situation where we have several markers overlapping each other, specifically map is zoomed out. If we tap on marker it should return the top most but it is not returning the top marker.

Example: Consider there are four markers A, B, C and D overlapping, where D is at the top. If we tap on D it should return marker "D" but it is returning other than "D".

Is there any clue?

有帮助吗?

解决方案

When you have overlapping markers like this it's best to think about grouping or clustering them and then allowing users to select from the markers grouped at that location. There are some open source solutions like this one or this one that you can use. I had a similar issue and ended up building my own marker grouping class to handle sorting between people, places, and other objects.

The only other work around I can think of would be to store references to all your markers in a collection so that, on click of one marker, you could search for others at the same location. If you were able to then distinguish between which marker is A and which marker is D you could manually trigger the click method for the marker you desire.

其他提示

I have a similar problem. I think Google does it on purpose to allow users to select the markers even if they are overlapped. I found one thing: if the topmost marker wasn't tapped previously then this topmost marker will be selected. On the other hand if it was already tapped (even if it's not selected anymore) then the overlapped one will be selected. The workaround I used is to remember all your markers positions, remove them from map and add again. In this case MapView doesn't seem to remember which one was tapped and selects the topmost. I also wonder if there's a way to just turn this behavior off?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top