Reputation: 177
I have an activity with a Google Map and some markers placed on the map. Additionaly, i have some TextViews that shows info from the first selected marker on the map.
I want to be able to access information from any selected marker from my map. I want my information from my Textviews to change when I click another marker. Can you tell me what method should I call or what should I do to be able to do that?
Thank you.
Upvotes: 1
Views: 6455
Reputation: 14810
Check the docs
and to get the marker title and marker snippet check these links
Add the marker as follows
myMarker = getMap().addMarker(new MarkerOptions()
.position(latLng)
.title("My Spot")
.snippet("This is my spot!"));
then, set the TextView
using getTitle()
or getSnippet()
as follows
tv.setText(myMarker.getTitle());
or
tv.setText(myMarker.getSnippet());
and
to change the text of the TextView
each time you click the marker detect the clicks with an onClickListener()
. May be like this..
map.setOnMarkerClickListener(new OnMarkerClickListener()
{
@Override
public boolean onMarkerClick(Marker arg0) {
if(marker.isInfoWindowShown()) {
marker.hideInfoWindow();
} else {
marker.showInfoWindow();
}
tv.setText(myMarker.getTitle()); //Change TextView text here like this
return true;
}
});
Upvotes: 5