How to eliminate colliding markers in Google Maps

2019-06-28 05:19发布

I should show a set of markers on map to indicate nearby points of interest. These markers will open public chat rooms by click and therefore I think the users should see short address information about each marker before entering that room without the need to click on the marker. However, if I change marker icons in that sense, some of the markers may collide as you can see below:

enter image description here

What I want to do is showing as many as possible markers without collision and replace the icon of these colliding ones with a very small marker like a dot (and no address information):

enter image description here

I achieved to get this result by performing x-axis sweep algorithm to detect collisions but unfortunately, if a marker stops colliding after the user scrolls the map or it exists from the screen or another markers enters the screens and begins to collide with other markers or the user scrolls to a completely new area,.. this algorithm should be performed again and again at every turn. To eliminate the majority of colliding markers I make use of maps-utils marker clustering but I need a more painstaking methodology to overcome this issue. I consider to implement quadtree but I could not be sure whether it is the best way or not. Any advice?

Example:

enter image description here

3条回答
等我变得足够好
2楼-- · 2019-06-28 05:30

Google Maps Android Marker Clustering Utility from https://developers.google.com/maps/documentation/android-api/utility/marker-clustering does this.

查看更多
太酷不给撩
3楼-- · 2019-06-28 05:38

IMHO, the best way could be combining zoom level, quad-tree and collision detection. So, in this scenario

Here, quad-tree will be used to reduce size of items(markers) to be performed collision detection algorithm. Because you should interest with only near markers, not whole markers individually.

If you detect colliding items by zoom level (not for only visible region/bounds as you did), you will not face the problems related below

if a marker stops colliding after the user scrolls the map or it exists from the screen or another markers enters the screens and begins to collide with other markers or the user scrolls to a completely new area

查看更多
Animai°情兽
4楼-- · 2019-06-28 05:46

You can try to remove: mGoogleMap.setMyLocationEnabled(true);

查看更多
登录 后发表回答