【问题标题】:How to resize the google map markers based on the google map different zoom level in android如何在android中根据谷歌地图不同的缩放级别调整谷歌地图标记的大小
【发布时间】:2019-05-21 22:26:27
【问题描述】:

我在 google map android 中使用了 5 个标记,并且每 5 秒标记位置也随着动画而改变。在这种情况下,我想根据缩放级别动态调整图标的大小。

【问题讨论】:

标签: android google-maps-markers marker


【解决方案1】:

试试下面的代码 sn-p,它是用来对付我的。此方法将返回适合您的缩放级别和预期高度和宽度的图像。

public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
}

【讨论】:

    【解决方案2】:

    您可以通过创建具有自定义高度的位图来做到这一点

    int height = 100;// resize according to your zooming level
    int width = 100;// resize according to your zooming level
    BitmapDrawable bitmapdraw = (BitmapDrawable)getResources().getDrawable(R.mipmap.marker);
    Bitmap b=bitmapdraw.getBitmap();
    Bitmap finalMarker= Bitmap.createScaledBitmap(b, width, height, false);
    

    并在地图上添加这个位图。

     map.addMarker(new MarkerOptions()
                    .position(POSITION)
                    .title("Your title")
                    .icon(BitmapDescriptorFactory.fromBitmap(finalMarker))
            );
    

    希望这行得通!

    【讨论】:

      猜你喜欢
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多