Android Question Marker bitmap size [SOLVED]

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,
I am raising a question that has been asked many times in in the distant past in the hope that there has been a solution that I haven't seen on the forum.

When using a bitmap with AddMarker3 or googlemapsextras the size of the bitmap varies between devices of different screen size or pixel density. IE There is no DIP for sizing.

I came up with my own rough workaround about 4yrs ago but was hoping there was now some improvement.

Please don't ask me to upload the project, as I said I have a workaround. If you know of a real fix let me know, if not, I will stick with what I have.

Regards Roger.
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
Erel,

Sorry about the delay getting back, my old 10" tablet is no more, I had to seek out a second device to compare.
The bad news, I could not get the code you suggested to work.

Test sample below:
B4X:
Sub MapFragment1_Ready
   gmap = MapFragment1.GetMap
  
   Private BitMap1 as BitMap   = (LoadBitmap(File.DirAssets, "smiley.png"))
   Private BitMap2 as BitMap =  (SetBitmapDensity(LoadBitmap(File.DirAssets, "smiley.png")))
  
   Log(BitMap1.Width = "& BitMap1.Width)   ' "120"  on both devices
   Log(BitMap2.Width = "& BitMap2.Width)   ' "120"
  
   ' [LG V20] The width of both BitMaps is the same,  therefore the physical size of the 2 icons is the same on the screen. 
   '[Note 3] The width  of the BitMaps is the same as on the LG V20 but the physical size is larger.
  
  
   Private m1 As Marker = gmap.AddMarker3(10, 30, "test", BitMap1)
   m1.Snippet = "This is the snippet"
  
   Private m2 As Marker = gmap.AddMarker3(10, 30, "test", BitMap2)
   m2.Snippet = "This is the snippet"
End Sub

Sub SetBitmapDensity(b As Bitmap) As Bitmap
   Dim jo As JavaObject = b
   Dim den As Int = Density * 160
   jo.RunMethod("setDensity", Array(den))
   Return b
End Sub

I have another lead, I will post in this thread if successful.


Regards Roger
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All

I have found the answer to the question. LoadBitMapResize has previously flown below my radar, once found the answer is obvious.
LoadBitMapResize allows you to resize images using DIP. The code below demonstrates this.

B4X:
Sub MapFragment1_Ready
   gmap = MapFragment1.GetMap
 
   Private BitMap1 as BitMap   = LoadBitmapResize(File.DirAssets, "smiley",25dip,25dip,True)
   Private BitMap2 as BitMap =  LoadBitmapResize(File.DirAssets, "smiley2",25dip,25dip,True)

   Private m1 As Marker = gmap.AddMarker3(10, 30, "test", BitMap1)
   m1.Snippet = "This is the snippet"
 
   Private m2 As Marker = gmap.AddMarker3(10, 35, "test", BitMap2)
   m2.Snippet = "This is the snippet"
End Sub

I have tried this code on a LG V20 and a Galaxy Tab A 10.1" and the markers were the same physical size.
I have also used GoogleMapsExtras with the same success.   [I use GoogleMapsExtras to set the anchor to the centre of the marker]

Many thanks to Erel for his usual support.


Regards Roger
 
Upvote 0
Top