具有自定义标记的android Maps API v2

我想用自定义标记制作地图。在API v2中,我可以为标记设置图标,标题等。但是我想在第一次发病时用标记显示标题。现在,仅当我点击标记时才显示标题。在v1中有叠加层,但是在v2中我没有发现任何类似的东西。


编辑: 也许我不够清楚。Marker.showInfoWindow()API中的某些功能仅适用于一个标记。我无法同时显示所有标记的信息窗口。无论如何,我需要显示所有标记的标题,而无需等待用户点击它。


吃鸡游戏
浏览 427回答 3
3回答

达令说

终于做到了。因此,您要做的是有一个背景图像(在我的情况下,我仅使用一个蓝色矩形)。像这样创建一个标记:Marker myLocMarker = map.addMarker(new MarkerOptions()            .position(myLocation)            .icon(BitmapDescriptorFactory.fromBitmap(writeTextOnDrawable(R.drawable.bluebox, "your text goes here"))));请注意writeTextOnDrawable()方法:private Bitmap writeTextOnDrawable(int drawableId, String text) {    Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId)            .copy(Bitmap.Config.ARGB_8888, true);    Typeface tf = Typeface.create("Helvetica", Typeface.BOLD);    Paint paint = new Paint();    paint.setStyle(Style.FILL);    paint.setColor(Color.WHITE);    paint.setTypeface(tf);    paint.setTextAlign(Align.CENTER);    paint.setTextSize(convertToPixels(context, 11));    Rect textRect = new Rect();    paint.getTextBounds(text, 0, text.length(), textRect);    Canvas canvas = new Canvas(bm);    //If the text is bigger than the canvas , reduce the font size    if(textRect.width() >= (canvas.getWidth() - 4))     //the padding on either sides is considered as 4, so as to appropriately fit in the text        paint.setTextSize(convertToPixels(context, 7));        //Scaling needs to be used for different dpi's    //Calculate the positions    int xPos = (canvas.getWidth() / 2) - 2;     //-2 is for regulating the x position offset    //"- ((paint.descent() + paint.ascent()) / 2)" is the distance from the baseline to the center.    int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)) ;      canvas.drawText(text, xPos, yPos, paint);    return  bm;}public static int convertToPixels(Context context, int nDP){    final float conversionScale = context.getResources().getDisplayMetrics().density;    return (int) ((nDP * conversionScale) + 0.5f) ;}
打开App,查看更多内容
随时随地看视频慕课网APP