1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question How Put a Label in Google Maps

Discussion in 'Android Questions' started by rafaelmotaquintana, Aug 20, 2019.

  1. rafaelmotaquintana

    rafaelmotaquintana Active Member Licensed User

    I have a google map working fine. I just need to put a label from top left of the map.
    I've read that creating a bitmap with the label then add a marker, but I don't know the coordinates, unless the user pulse the map in a long click, and I don't want that.
    Any help would be greatly appreciated
     

    Attached Files:

  2. DonManfred

    DonManfred Expert Licensed User

    You can place a trasnparent panel over the map.
    Use a canvas then to draw on this panel using the panel as canvastarget
    WhatsApp Image 2019-08-20 at 14.52.35.jpeg
    Code:
    canvastest.Initialize(pnlcanvas)
        canvastest.DrawText(
    "Testtext",25dip,25dip,Typeface.DEFAULT,20,Colors.Blue,"LEFT")
     
    rafaelmotaquintana likes this.
  3. DonManfred

    DonManfred Expert Licensed User

    i also tried to place a label over the map in the layout. It does work too. At least for me?

    [​IMG]

    WhatsApp Image 2019-08-20 at 15.02.49.jpeg
     
  4. rafaelmotaquintana

    rafaelmotaquintana Active Member Licensed User

    Perfect. Could the whole thing be saved in a bitmap?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    GoogleMapsExtra includes a snapshot method that you can use. Once you get the map bitmap it should be some to add the label.
     
    rafaelmotaquintana likes this.
  6. rafaelmotaquintana

    rafaelmotaquintana Active Member Licensed User

    Ok, I'll try. Thanks
     
  7. rafaelmotaquintana

    rafaelmotaquintana Active Member Licensed User

    I did the snapshot. Then use this code:
    Code:
    Sub MapDrawlabel1_SnapshotReady(Bitmap1 As Bitmap)
        
    Private c As Canvas, b As Bitmap
        b = Bitmap1
        c.Initialize2(b)
        c.DrawText(
    "Testtext",25dip,25dip,Typeface.DEFAULT,20,Colors.Blue,"LEFT")
        
    Private out As OutputStream
        out = 
    File.OpenOutput(FolderImagesLogo, "MAPA1.png"False)
        b.WriteToStream(out, 
    100"PNG")
        out.Close
    End Sub
    Map is saved. But with no text. Something I'm missing?
     
  8. DonManfred

    DonManfred Expert Licensed User

    Code:
    Sub Mapextra_SnapshotReady(Bitmap1 As Bitmap)
        
    Log($"Mapextra_SnapshotReady()"$)
        
    Dim cvs As Canvas
        cvs.Initialize2(Bitmap1)
        cvs.DrawText(
    "Testtext",25dip,25dip,Typeface.DEFAULT,20,Colors.Blue,"LEFT")

        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
        
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
      
        
    Dim Out As OutputStream
        Out = 
    File.OpenOutput(File.DirRootExternal, "Test.png"False)
        cvs.Bitmap.WriteToStream(Out, 
    100"PNG")
        Out.Close
    End Sub
     
    Last edited: Aug 21, 2019
    rafaelmotaquintana likes this.
  9. rafaelmotaquintana

    rafaelmotaquintana Active Member Licensed User

    Sorry. I found it. It Works
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice