不知道这是你脑子里想的是什么,但在这里不用
创建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:我已经看到了这些。标题属性仅在用户点击标记时显示 –