2013-07-30 22 views
0

我希望使用可编辑的标题和片段将标记添加到GoogleMap。当用户长时间点击地图时,标记应该出现,然后标记应该出现显示“点击编辑”之类的标题。在标记创建时显示标题和片段

代码全部运行起来,除了我不知道如何让标题在创建标记时出现。我只能让它出现,随后点击标记。我在MarkerOptions中看不到任何允许我这样做的内容。我错过了什么?

回答

4

您寻找的选项不在MarkerOptions它是Marker本身的功能。 Here's a link to the related docs

marker.showInfoWindow(); 

要调用这个方法,你需要有标记,或者对它的引用。如果你在创作时这么做,应该很简单。否则,只需将您的制造商存储在某个集合中即可 - 例如HashMap,因此它们很容易找到 - 并且您可以随时显示信息窗口。

0

如果您想以自己的自定义方式显示标记的标题和片段 - 您可以将其设置在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>