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?
Related
If i make a tap on the map on a marker, an event gets triggered and i can catch it implementing the interface `OnMarkerClickListener. The event return me the marker on which i tapped; this is straightforward. The problem i'm facing now is that when there are 2 or more marker one on top of another, i don't know on which marker will be triggered the event. I already excluded the possibility that the first marker to be drew is the first to be selected and it seems like the choice is made at randoms, but i think this is not the case.
I would like to know how the API choose on which marker to trigger the event, between the "n" overlapping marker, and how i can control this choice.
I must say that due to some logic in my app i would like to not use Spinderfier or Marker clustering to avoid Marker overlapping; i also found this workaround to eliminate the problem i can't use it.
Sorry for my poor English and thank you for your attention.
I am tracking my employees position on google map what I want to do is
to move the marker from its old position to a new position.
I am using this library for the cluster marker and the custom marker icons.
I want to move the marker from one position to another one, like other apps move their icons like any online cab application
Please help me, it's very important for me.
If you want to move the Marker along with the user interactions on the map something like few Cab Service do, you can refer the below link for the solution :
Map style like other Cab Service
I am doing a little project on Android with Google maps. And I have one question - it is possible to make marker draggable with single click on it, not after long press. For example: I click marker, it changes icon and I can drag it anywhere in map, and then after another tap he will not be draggable again and changes its icon back? (Marker must be draggable all the time from first tap to second even if you release it)
#user2595870:
Hello,
I know it should be in comment but due to less reputations i am suggesting you in answer.
You want to drag and drop facility for marker kind of thing ?
if so there is good example provided here. Please check it.
I have a google map in an android application, using API V2, and I've run into a slight problem. I'm loading all Markers in the visible map area from a database. That part is running fine, as is clicking them, and clicking their info windows.
The problem is, once I have the info window click event captured, I want to send the represented database object to another activity. How do I get that. I was thinking latlng of the marker, but it appears to have been adjusted/truncated when put on the map. So I was thinking of using the name of the building, but what if two buildings have the same name. I was thinking subclassing Marker and giving mine an id, but Marker is a final class.
For now I'm going to settle on a name/address kind of search, but I'd prefer something a little more definitive to the specific object the marker represents. How do I store extra data in a marker?
I want each marker on the map (Map View) with different id so that I can remove it or change its icon dynamically at run time.
How do we achieve that ?
Also please I want the best way to add many markers on the map without making it slow when moving it on taping over it.
Thanks in advance
How do we achieve that ?
Subclass OverlayItem and store whatever you want in it, using that instead of the ordinary OverlayItem class for your items. For example, this sample project has a CustomItem subclass of OverlayItem that, among other things, draws different icons at runtime.
Also please I want the best way to add many markers on the map without making it slow when moving it on taping over it
Don't "add many markers" to an ItemizedOverlay, to the point where it is "when moving it on taping over it". ItemizedOverlay is designed for small numbers of items.
If you need lots of items, you will most likely need to create your own Overlay, where you can have more smarts about which subset of your items will be relevant at any given time.