3

I have a used custom marker in my Google Map App with help of Bitmap and canvas . The image on marker is coming fine when i run it on device with android version 5.1 or any other except 4.4.

I am sure its not a version issue . but i am confused and unable to figure out where i done mistake . Please help me to find it .

Custom marker (Bitmap) Code:

Bitmap.Config conf = Bitmap.Config.ARGB_8888;
            Bitmap bmp = Bitmap.createBitmap(128, 128, conf);
            Canvas canvas1 = new Canvas(bmp);


    canvas1.drawBitmap(BitmapFactory.decodeResource(getResources(),
                        R.drawable.map_markers_green), 0, 0, color);

                canvas1.drawText(String.valueOf(a).toUpperCase(), 56, 53, color);
                googleMap.addMarker(new MarkerOptions()
                        .icon(BitmapDescriptorFactory.fromBitmap(bmp))
                                // Specifies the anchor to be at a particular point in the marker image.
                        .anchor(0.5f, 1));

Marker image which is working fine on device:

enter image description here

Same marker image which is coming cut on different device :

enter image description here

young_08
  • 1,196
  • 2
  • 13
  • 35

1 Answers1

2

Try this code

Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmp = Bitmap.createBitmap(200, 50, conf); 
 Canvas canvas = new Canvas(bmp);
canvas.drawText("TEXT", 0, 50, paint); // paint defines the textcolor, stroke width, size
 mMap.addMarker(new MarkerOptions()
                            .position(clickedPosition)
                            //.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker2))
                            .icon(BitmapDescriptorFactory.fromBitmap(bmp))
                            .anchor(0.5f, 1)
                                );
Vishal Thakkar
  • 2,117
  • 2
  • 16
  • 33
  • No , problem still same with this code as well . Not working for me . – young_08 Jan 13 '16 at 10:21
  • try this Link solution (http://stackoverflow.com/questions/14811579/how-to-create-android-map-api-v2-custom-marker-with-imageview) – Vishal Thakkar Jan 13 '16 at 10:28
  • i have done same in my code that's why its working fine on same devices . But in some devices , the marker get cut off for some reason . – young_08 Jan 13 '16 at 10:32
  • you put all size image in drawable.? – Vishal Thakkar Jan 13 '16 at 10:36
  • yes , i did . I have used hit and trial method with almost every size image but problem remain same . My custom marker getting cut off . – young_08 Jan 13 '16 at 10:37
  • There is also a thing , it might get solved by increasing width and height in Bitmap . But doing these changes will create problem on devices which working fine with this code . – young_08 Jan 13 '16 at 10:39
  • try on draw text method put 0 instead of 56 and on create bitmap method second parameter put 32 instead of 128 – Vishal Thakkar Jan 13 '16 at 10:45
  • Vishal , but changing bitmap and draw method will create issue on devices on which this code working fine . Thats why i am reluctant to change it . I want to modify it in a way that work fine on every device . – young_08 Jan 13 '16 at 10:49
  • yes . I have taken help from your code and applied to mine . And it resolved . – young_08 Jan 29 '16 at 07:11