Android Question Bitmap centered at GoogleMaps Marker position

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to All
my problem is that I would like to draw a simbol centered at a given Marker, in a GoogleMaps map. For example, let's assume that the symbol is a rectangle. I use a canvas to draw the rectangle in a Bitmap. The code was written by Erel in another post, for drawing a text on a marker, and I report it hereunder, modified for my needs, just drawing a rectangle:
B4X:
Sub CreateBitmap(text As String) As B4XBitmap
    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    Dim colore As Int : colore=Colors.Red
    Dim larg,alt As Int
    Dim font As B4XFont
    Dim c As B4XCanvas

    font=xui.CreateDefaultFont(20) ' just used for getting a suitable size
   
    larg=text.Length*font.Size 
    alt=font.Size 
   
    p.SetLayoutAnimated(0, 0, 0, larg, alt)
   
    c.Initialize(p)
     
     c.DrawRect(c.TargetRect,colore,False,2)
     
    Return c.CreateBitmap
End Sub
With this code, the rectangle is drawn centered on X, with respect to marker position, but "above" the Marker, as shown in the attached image (44.png)
The yellow line connects Markers positions. What I am not able to do, is to draw a rectangle centered at the Marker position. I begin to think that I must change the following AddMarker3 call, using Latitude and Longitude modified to shift the rectangle with respect to the marker position. This seems a rather tricky solution, because the offsets are in meters.
The function CreateBitmap is called with:
B4X:
gmap.AddMarker3(Latitude, Longitude, Name,CreateBitmap(Name)) ' Name is a text not used in the called funcion
 

Attachments

  • 44.png
    44.png
    70.1 KB · Views: 145

Magma

Expert
Licensed User
Longtime User
Upvote 0

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
...Actually you want align icon of Marker at center ?

You can use MarkerExtras (GoogleMapsExtras) for this:

B4X:
Dim mx As MarkerExtras
mx.SetAnchor(Marker, 0.5, 0.5) 'center...
yes. it is what I looked for. It works. Thanks a lot.?
 
Upvote 0
Top