不知道這是你腦子裏想的是什麼,但在這裏不用
創建MarkerOptions
對象:
MarkerOptions options = new MarkerOptions()
.title(name)
.position(source)
.icon(gettIconFromDrawable(myMarker))
.snippet("Briefly describe \nyour content here");
然後標記添加到地圖
Marker sourceMarker = mMap.addMarker(options);
創建InfoWindowAdapter
以容納摘錄中的多行。 (原來這裏的answer)
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
Context context = getApplicationContext(); //or getActivity(), YourActivity.this, etc.
LinearLayout info = new LinearLayout(context);
info.setOrientation(LinearLayout.VERTICAL);
TextView title = new TextView(context);
title.setTextColor(Color.BLACK);
title.setGravity(Gravity.CENTER);
title.setTypeface(null, Typeface.BOLD);
title.setText(marker.getTitle());
TextView snippet = new TextView(context);
snippet.setTextColor(Color.GRAY);
snippet.setText(marker.getSnippet());
info.addView(title);
info.addView(snippet);
return info;
}
});
最後,添加該屬性,以保證標記保持可見
sourceMarker.showInfoWindow();
您可以檢查這些https://stackoverflow.com/questions/17989389/label-at -The-top-of-the-marker-in-google-maps-api-v2 –
@NavjotSingh:我已經看到了這些。標題屬性僅在用戶點擊標記時顯示 –