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?
Related
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:
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):
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:
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
Google Maps Android Marker Clustering Utility from
https://developers.google.com/maps/documentation/android-api/utility/marker-clustering does this.
You can try to remove:
mGoogleMap.setMyLocationEnabled(true);
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
I'm developing an application that has the following goal:
Using the google maps android API 2 I get my current position, and as I start walking the application starts drawing the route I take
The twist is that the map is a "blind" map. Meaning the map is hidden, only the Marker of my current position and a dotted line of my route is shown.
Keep in mind I'm a novice developing to Android, so please be specific. (Thank you)
I managed to create the map, get my current position and zoom in to it (Had no sens to see the whole planet while i want only my current position). And it's pretty accurate so far.
The thing is I don't know what should I do from this point on.
Basicly I need a white View between the Marker and the real map. Also as I advance that View should always be on, over the MapFragment/MapView. Also I wish to keep the zoom and drag functionality's of the MapFragment.
How can I achieve this?
At this point I'm opened to any solutions.
(Been browsing for a few days now the developers site, I have seen that with the ViewOverlay class I can put messages over the map, but I'm not sure what would the correct aproach be in my case...)
To hide the whole map behind the white view I would use Polygon class Polygon Even if you specify Polygon to cover the whole map Markers will be still displayed in front of it and as so user's current position marker will be visible. You also will be able to zoom and drag.
To draw line on map use Polyline class Polyline It will draw users path as a polyline. If you want to stick with dotted line you can use Circle objects to create it. Circle
In my app I want to draw a route between a selected marker displayed in my map and my current location.
I am working with fragments and it is a little bit confusing; I can't find any method that returns the current location in a fragment. I've searched for two days with no result. My map works with markers, but I don't know the right method that works with fragments.
The easiest way to get current location out of Android map v2 - is to use GoogleMap#getMyLocation() interface (EDIT - just noticed it is deprecated already:)). If this is not enough for you - there is more complex and flexible way - http://developer.android.com/training/location/retrieve-current.html
Drawing path between your current location and specified marker is simple as well. Just look at the GoogleMap.addPolyline() interface.
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.