B4J Question Setting the size of an icon with AddMarker2

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I am displaying custom marker icons which are held on a server in a B4 App using AddMarker2.

This works fine except for the size of the images.

In B4A & B4I, I can specify a size for the image icon, but with B4J I cannot.

Looking at the Google documentation, it is possible to set the icon size with an icon object.
https://developers.google.com/maps/documentation/javascript/reference/marker#Icon

Can anyone tell me how to get access these fields.


Thanks

Andrew
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Example:
B4X:
Dim m As Marker = gmap.AddMarker(30, 30, "test")
Dim jo As JavaObject = m
jo.GetFieldJO("jsObject").RunMethod("eval", Array($"
 var image = {
   url: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png',
    size: new google.maps.Size(16, 16),
    origin: new google.maps.Point(0, 0),
    anchor: new google.maps.Point(0, 16)
   };

   this.setIcon(image);
"$))
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Thanks @Erel,
it would seem that you also need to include scaledSize as well or you only get a portion of the icon.

B4X:
Sub AddSizedMarker(g As GoogleMap,lat As Double,lng As Double, title As String, iconuri As String, iconsize As Int) As Marker
    Dim m As Marker = g.AddMarker(lat,lng, title)
    Dim jo As JavaObject = m
    jo.GetFieldJO("jsObject").RunMethod("eval", Array($"
 var image = {
   url: '${iconuri}',
    size: new google.maps.Size(${iconsize},${iconsize}),
    scaledSize:new google.maps.Size(${iconsize},${iconsize}),
    origin: new google.maps.Point(0, 0),
    anchor: new google.maps.Point(0, ${iconsize/2})
   };

   this.setIcon(image);
"$))

 Return m
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…