我想在不点击标记的情况下显示谷歌地图中所有标记的每个标记标题和片段,也就是说,默认情况下,它应该显示所有标记,这是想要实现的吗?
如何在谷歌地图V3中永久显示标记的标签/标题?
根据文献记载,有一种方法showInfoWindow()
,但只显示一个标记,如何对所有标记执行此操作?或者有没有其他方法可以在不点击的情况下显示标记信息?
对于具有标题的多个标记,请在活动的onMapReady方法上写下以下代码。
希望这能帮助。。。
for (int i = 0; i < listOfMarkers.size(); i++) {
LatLng latLng = new LatLng(listOfMarkers.get(i).latitude,listOfMarkers.get(i).longitude);
Marker mk = googlemap.addMarker(new MarkerOptions()
.position(latLng)
.icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmapFromView(listOfMarkers.get(i).getTitle());
}
}
private Bitmap getMarkerBitmapFromView(String resId) {
View customMarkerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.map_item_textview, null);
TextView markerImageView = (TextView) customMarkerView.findViewById(R.id.tv_map_item_price);
markerImageView.setText(resId);
markerImageView.setTextColor(Color.parseColor("#000000"));
customMarkerView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
customMarkerView.layout(0, 0, customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight());
customMarkerView.buildDrawingCache();
Bitmap returnedBitmap = Bitmap.createBitmap(customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(returnedBitmap);
canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC_IN);
Drawable drawable = customMarkerView.getBackground();
if (drawable != null)
drawable.draw(canvas);
customMarkerView.draw(canvas);
return returnedBitmap;
}