简体   繁体   English

我如何从选定的标记中获取信息? (Android)

[英]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. 谢谢。

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 然后,使用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.

相关问题 如何从 Android 上的 firebase 获取标记信息? - How to get the information of a marker from firebase on Android? 如何从Android的微调器中选择“ itemsid”? - How can I get selected “itemsid ” from spinner in Android? 如何从android中的webview获取选定的文本? - How can I get selected text from webview in android? 如何在Android Studio中以字符串形式获取地图标记的位置? - How can I get the location, as a string, of a map marker in Android studio? 从标记Google Maps-Android Studio获取所有信息 - get all the information from a marker google maps-android studio 如何从 Google 地图中的可拖动标记中获取 position? - How can I get position from a draggable marker in Google Maps? 我可以从 Android 设备信息屏幕获取捕获的图像吗? - Can I get a captured image from the Android device information screen? 我可以从Android浏览器JavaScript获得什么信息? - What information can I get from the android browser JavaScript? 如何从Shell获取有关Android Shell中可用命令的信息? - How can I get information from the shell about commands available in Android shell? 如何在 Android 中使用 SQLite 从微调器中根据选定的月份和年份从列中获取值? - How can I get values from a column based on selected month and year from spinner using SQLite in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM