简体   繁体   中英

How can i get information from a selected marker? (Android)

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.

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;
      }
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM