如何创建自定义 Android 地图标记?

发布于 2024-09-24 22:35:44 字数 180 浏览 2 评论 0原文

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

OverlayItem.setMarker() 仅接受可绘制对象。

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

有什么想法吗?

I want to create a mapview marker with 4 elements:
- picture (of user)
- background
- text (username)
- Arrow to show an direction

OverlayItem.setMarker() accept only a drawable.

How can I create an drawable with 4 Items? Or can i add an View as marker to overlayItem?

any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终难遇 2024-10-01 22:35:45

我找到了解决办法。
我创建了一个 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);

I have found a solution.
I create a BitmapDrawable

Here is the code

        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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文