【发布时间】:2013-07-30 12:34:32
【问题描述】:
我希望在 googleMap 中添加一个带有可编辑标题和 sn-p 的标记。当用户在地图上长按时,标记应该会出现,然后标记应该会显示类似“点击编辑”的标题。
代码已全部启动并运行,只是我不知道如何在创建标记时显示标题。我只能通过随后单击标记使其出现。我在 MarkerOptions 中看不到任何允许我这样做的东西。我错过了什么吗?
【问题讨论】:
标签: android google-maps
我希望在 googleMap 中添加一个带有可编辑标题和 sn-p 的标记。当用户在地图上长按时,标记应该会出现,然后标记应该会显示类似“点击编辑”的标题。
代码已全部启动并运行,只是我不知道如何在创建标记时显示标题。我只能通过随后单击标记使其出现。我在 MarkerOptions 中看不到任何允许我这样做的东西。我错过了什么吗?
【问题讨论】:
标签: android google-maps
您要查找的选项不在MarkerOptions 中,它是Marker 本身的函数。 Here's a link to the related docs
marker.showInfoWindow();
要调用此方法,您需要有标记或对它的引用。如果您在创建时执行此操作,它应该很容易。否则,只需将您的制造商存储在某个集合中 - 例如HashMap,以便轻松找到它们 - 您可以随时显示信息窗口。
【讨论】:
如果您想以自己的自定义方式显示标记的标题和 sn-p - 您可以在 onMapReadyCallback 中设置它。
@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
mGoogleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View view = getLayoutInflater().inflate(R.layout.marker_info, null);
TextView textViewTitle = (TextView) view.findViewById(R.id.marker_title);
textViewTitle.setText(marker.getTitle());
TextView textViewSnippet = (TextView) view.findViewById(R.id.marker_snippet);
textViewSnippet.setText(marker.getSnippet());
return view;
}
});
这是我的布局文件。marker_info.xml。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/marker_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"/>
<TextView
android:id="@+id/marker_snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
</LinearLayout>
【讨论】: