簡體   English   中英

Google Maps Custom Marker Android

[英]Google maps custom marker android

我正在基於Android的Google Maps服務制作一張公共交通地圖。 地圖應包含許多標記(超過300個),並且在地圖放大和縮小(縮放)時應調整其大小。 現在,標記只是彼此重疊,有沒有辦法創建這樣的自定義標記?

示例圖片

我已經嘗試過自己,但沒有成功。 有了android-map-utils庫( https://github.com/googlemaps/android-maps-utils ),標記現在看起來更好了,但是它們不可調整大小且看起來不同。

准則:-標記包含一個點,該點指向所需的位置,文本位於該點的右側或左側-標記應隨地圖調整大小。

使用位圖比例

Bitmap markerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_marker,options);
markerBitmap = SubUtils.scaleBitmap(markerBitmap, 70, 70);

然后將其設置為您的Markeroptions

MarkerOptions marker = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(markerBitmap));
Marker mark = googleMap.addMarker(marker);

編輯

這是scaleBitmap方法

public static Bitmap scaleBitmap(Bitmap bitmap, int newWidth, int newHeight) {
        Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888);

        float scaleX = newWidth / (float) bitmap.getWidth();
        float scaleY = newHeight / (float) bitmap.getHeight();
        float pivotX = 0;
        float pivotY = 0;

        Matrix scaleMatrix = new Matrix();
        scaleMatrix.setScale(scaleX, scaleY, pivotX, pivotY);

        Canvas canvas = new Canvas(scaledBitmap);
        canvas.setMatrix(scaleMatrix);
        canvas.drawBitmap(bitmap, 0, 0, new Paint(Paint.FILTER_BITMAP_FLAG));

        return scaledBitmap;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM