我希望使用可編輯的標題和片段將標記添加到GoogleMap。當用戶長時間點擊地圖時,標記應該出現,然後標記應該出現顯示「點擊編輯」之類的標題。在標記創建時顯示標題和片段
代碼全部運行起來,除了我不知道如何讓標題在創建標記時出現。我只能讓它出現,隨後點擊標記。我在MarkerOptions中看不到任何允許我這樣做的內容。我錯過了什麼?
我希望使用可編輯的標題和片段將標記添加到GoogleMap。當用戶長時間點擊地圖時,標記應該出現,然後標記應該出現顯示「點擊編輯」之類的標題。在標記創建時顯示標題和片段
代碼全部運行起來,除了我不知道如何讓標題在創建標記時出現。我只能讓它出現,隨後點擊標記。我在MarkerOptions中看不到任何允許我這樣做的內容。我錯過了什麼?
您尋找的選項不在MarkerOptions
它是Marker
本身的功能。 Here's a link to the related docs
marker.showInfoWindow();
要調用這個方法,你需要有標記,或者對它的引用。如果你在創作時這麼做,應該很簡單。否則,只需將您的製造商存儲在某個集合中即可 - 例如HashMap
,因此它們很容易找到 - 並且您可以隨時顯示信息窗口。
如果您想以自己的自定義方式顯示標記的標題和片段 - 您可以將其設置在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>