I am using a for loop to make markers on maps based on locations retrieved from database.
I have a layout with two TextViews that i want to fill with the marker's name and address(retrieved from database).
I tried using googleMap.setInfoWindowAdapter() but all it did was changing the layout for all markers altogether (which is obviously NOT what i need).
So is there a way to allow me to change the info window of each marker independently?
Implement onMarkerClickListener. Get the marker object as follows
You will get your marker in overridden method when you click on it. Get the title and snippet from it as follows.
Good luck :)
The simplest way to show two lines of text is to use built-in support for info window. When setting title and snippet on each marker, you will have them shown after clicking
Marker
if you don't set your ownInfoWindowAdapter
.If your address is multiline text, then the above won't work correctly and you need to provide you own
InfoWindowAdapter
implementation. When doing that just useMarker
parameter sent togetInfoContents
orgetInfoWindow
: retrieve title and snippet from it and put inside yourTextViews
usingsetText
.When having more than 2 texts to show or other data types, it complicates even futher, but if you need it at some point, take a look at this answer: Android google maps add to marker own tag