简体   繁体   中英

Google maps custom marker android

I'm making a public transportation map based on Google Maps service for Android. The map should contain a lot of markers (over 300) and they should resize when the map is zooming in and out (scale). Right now the markers just overlap each other, is there a way to create custom markers like this?

示例图片

I have tried myself, but have had no success. With android-map-utils library ( https://github.com/googlemaps/android-maps-utils ) markers now look better, but they aren't resizeable and look different.

Criteria: - Markers contain a dot that points on needed location and text on right or left side of dot - Markers should resize with map.

using bitmapscale

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

then set it to your Markeroptions

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

EDIT

here is scaleBitmap method

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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM