[英]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. 我正在使用Google地图进行活动,并在地图上放置了一些标记。 Additionaly, i have some TextViews that shows info from the first selected marker on the map. 另外,我有一些TextViews可以显示地图上第一个选定标记的信息。
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. 当我单击另一个标记时,我希望我的Textviews中的信息更改。 Can you tell me what method should I call or what should I do to be able to do that? 您能告诉我应该调用哪种方法,或者我应该怎么做才能做到这一点?
Thank you. 谢谢。
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 然后,使用getTitle()
或getSnippet()
设置TextView
,如下所示
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()
. 在每次单击标记时更改TextView
的文本,并使用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;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.