Sometimes when markers are really close to each other, it requires many clicks to zoom enough so that the cluster unfolds and shows all the markers individually.
How can I make it so that one click on a cluster always zooms in and unfolds it correctly?
If you wanted to zoom to show all the markers from a single cluster, you could end up showing only some of them. If that's ok with you, here are the steps (e.g. in onMarkerClick):
check if Marker.isCluster
loop over Marker.getMarkers
for every marker call GoogleMap.getMinZoomLevelNotClustered and remember the largest value from the loop
after loop call GoogleMap.animateCamera with some LatLng and the largest zoom value
The problem here is to decide what LatLng to choose. If you choose the one from cluster marker, you could even end up not showing any marker after zoom.
Alternatively you may want to zoom to LatLngBounds created from all the markers in the cluster. This will not make it to show all markers, but for sure you would end up with all markers still hidden somewhere on the screen.
Related
I am building an application which uses Google Maps. When displaying the map, I'm also adding markers. Is there a way to see if there are 2 markers that touch each other, meaning if a part of a marker is on top of another marker? My goal is to be able to find that out and then make them a single bigger marker instead of 2 different markers.
The answer should depend somehow on the marker's icon size and the current map zoom since if I zoom out, there's a bigger chance they might overlap.
There seem to be a library made by Google which clusters a set of markers together automatically when they are close to one another.
The library is the marker clustering utility and instruction can be found here:
https://developers.google.com/maps/documentation/android-api/utility/marker-clustering
In our application, a lot of markers are drawn in different locations and in certain cases at a certain zoom level, markers overlap each other. So when I click on the marker, I expect the top marker's onMarkerClick to be fired but instead it is fired for the last hidden marker i-e the last marker, with no markers behind it.
What do you suggest I do?
I’m plotting content on a GoogleMap using the map clustering utility library from google.
I have lots of items representing pictures. Depending on zoom level, they are clustered or not. I’m managing clustering with a DefaultClusterRenderer subclass.
At the same time, I want to draw a marker representing the device location. That is a totally different marker which should not be clustered. Because of that I’m dealing with this single marker outside the ClusterManager / ClusterRenderer cycle, i.e. calling mMap.addMarker().
The issue with that is that sometimes, depending on when we get the device location, and moreover during zoom in/out, my location marker is drawn below the other points and clusters. I want to have the exact opposite behavior, i.e. location marker always on top.
Is there a way to achieve that?
I have multiple markers set around on the map. What I want to know is how can I show only a few markers depending on the zoom level. For example: I have a zoom on the map with radius: the length between the center of the map and the bounds of the screen (lets say this is like 2km in real life not sure if this is true) so I want to show only the markers that are inside the radius. And of course if the user zooms out the radius will be recalculated again from the center point of the map to the bound of the screen. And again include markers that are inside the new radius. How can I achieve this?
I have thought about this problem and here could be an approach.
you can loop through your available markers and find distance from the center of your given circle (since we're talking about a radius) to the marker; this can be done using computeDistanceBetween(); for more info see link
If the marker lies within your radius, show, otherwise, hide using the setVisible() method. For more information, see link
Hope this gives you some idea.
I have faced some problems with the Android MapView API. I get OverlayItems from a database which I want to display in a MapView. If I'm displaying 100 Icons, I have no issues, but if it gets more - like 500 Items in one City - it first looks really bad, while second it slows down a lot. Unfortunately my goal is to display 10000 of them. I think one solution can be to register a listener to ZoomLevels to make them appear/dissapear, but I couldn't find that functionality. Second, I couldn't find a function to scale my Overlays with the Zoom of the Map.
Any Ideas are very welcome
There is a very strange behavior in ItemizedOverlay draw method. When you say: Draw line from (x,y) to (x1,y1) the draw method is called about 20-30-40 times - i don't know why. It is acceptable when you draw one line, but when you draw a thousands of lines,icons and so on...it is very very bad! To solve this problem you should create a cached overlay. This is overlay that catches the first draw, creates the object and then prevents the future draws that do the same draw.
A cluster is a dozen of icons behind one icon. For example if you have 1000 markers on the map, in a specific minimal zoom level you can not see each marker separately - it becomes a mess of icons and colors and so on. And instead of 100 markers that are very very close one by one you place a cluster marker. And on zoom in remove this cluster and create another clusters...do this until the markers became far enough away and you can seen them divided.
Check this: Cluster markers
Take the following approaches:
Create a cached overlay to prevent multiple drawing of same clusters;
Draw in thread;
Cluster your markers depending on zoom level and marker proximity.
Each time you draw in the overlay, check for sure is the current marker inside of the visible part of the screen. If it is not, do no draw it!
I had a similar problem with the icon size and zoom level in my application. What I ended up doing was having 2 sets of overlays containing the markers, one with a "zoomed in" icon and one with a "zoomed out" icon. Then just changed the overlay at a certain zoom level (using a zoom poller - On zoom event for google maps on android)