2

I want my android application to download images from the Internet and display markers with these images on a Google Map. I also have markers with the default marker. This works fine but on different devices the custom markers are not scaled correctly. Here is my current code:

        BitmapFactory.Options options = new BitmapFactory.Options();
        DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();

        float density = metrics.density + 1;

        if (density >= 4.0)
            options.inDensity = DisplayMetrics.DENSITY_XXXHIGH; // "xxxhdpi"
        else if (density >= 3.0)
            options.inDensity = DisplayMetrics.DENSITY_XXHIGH;  // "xxhdpi"
        else if (density >= 2.0)
            options.inDensity = DisplayMetrics.DENSITY_XHIGH;   // "xhdpi"
        else if (density >= 1.5)
            options.inDensity = DisplayMetrics.DENSITY_HIGH;    // "hdpi"
        else if (density >= 1.0)
            options.inDensity = DisplayMetrics.DENSITY_MEDIUM;  // "mdpi"
        else
            options.inDensity = DisplayMetrics.DENSITY_LOW;     // "ldpi"

        for(int i = 0; i < images_list.size(); ++i) {
            String icon = images_list.get(i).icon;
            if(icon.length() > 0) {
                String fileName = icon.substring(icon.lastIndexOf('/') + 1);
                File file = Utils.getImageFile(fileName);
                Bitmap markerBitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
                ...
            }

        }

The only place I found this question was here: https://www.b4x.com/android/forum/threads/googlemap-marker-size-problem.33841/ but nobody found a solution.

I would like my custom markers to be scaled the same way the default marker is.There is no way to get the current width and height of the default marker.

I can also replace the default marker with a custom one but this will not solve the scaling i.e. the default marker always looks good on all resolutions.

Any ideas ?

  • I solved it by using this scale method: http://stackoverflow.com/questions/4231817/quality-problems-when-resizing-an-image-at-runtime – Tsvetan Filev May 11 '17 at 14:16

0 Answers0