【问题标题】:how to create an custom android maps marker?如何创建自定义的 android 地图标记?
【发布时间】:2010-09-24 13:05:50
【问题描述】:

我想创建一个包含 4 个元素的地图视图标记: - 图片(用户) - 背景 - 文本(用户名) - 箭头显示方向

OverlayItem.setMarker() 只接受一个drawable。

如何创建包含 4 个项目的可绘制对象?或者我可以在 overlayItem 中添加一个 View 作为标记吗?

有什么想法吗?

【问题讨论】:

    标签: android android-mapview drawable google-maps-markers


    【解决方案1】:

    我找到了解决办法。 我创建了一个 BitmapDrawable

    这里是代码

            Bitmap photo = ((BitmapDrawable)mActivity.getResources().getDrawable(R.drawable.user_picture_dummy)).getBitmap();
    
            Bitmap returnedBitmap = Bitmap.createBitmap(Global.dipToPx(40), Global.dipToPx(67), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(returnedBitmap);
    
            mBackground.setBounds(0, Global.dipToPx(10), canvas.getWidth(), canvas.getHeight());
            mBackground.draw(canvas);
    
            m.postScale((float)Global.dipToPx(30)/(float)photo.getWidth(), (float)Global.dipToPx(30)/(float)photo.getHeight());
            m.postTranslate(Global.dipToPx(5), Global.dipToPx(15));
            canvas.drawBitmap(photo, m, paint);
            m.reset();
    
            canvas.drawText(Global.DateToTimeString(adv.getStartDateMS()), Global.dipToPx(20), Global.dipToPx(10), paint);
    
            mat.postRotate((float)bearingTo(adv.getDepGeoPoint(), adv.getArrLocationObj().getGeoPoint()), mDirection.getWidth()/2, mDirection.getHeight()/2);
            mat.postTranslate(canvas.getWidth()-mDirection.getWidth(), canvas.getHeight()-mDirection.getHeight()-Global.dipToPx(12));
            canvas.drawBitmap(mDirection, mat, paint);
            mat.reset();
    
            BitmapDrawable drawable = new BitmapDrawable(returnedBitmap);
            boundCenter(drawable);
    
            OverlayItem item = new OverlayItem(adv.getDepGeoPoint(), adv.getOwnerObj().getUserName(), adv.getOwnerObj().getUserName());
            item.setMarker(drawable);
    

    【讨论】:

    • 我认为这是 inclomplete 例如mat 来自哪里?它有什么类型?
    猜你喜欢
    • 2020-06-26
    • 2022-01-08
    • 2018-01-13
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多