GoogleMapExtra - Custom Annotation...

Discussion in 'Android Questions' started by cristianos, Jul 2, 2013.

  1. cristianos

    cristianos Member Licensed User

    does anyone know how to get a label with the image like in this photo?
    Tank's
    Cristiano
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried building it with Html?
     
  3. cristianos

    cristianos Member Licensed User

    no. should I use webview ... right??
     
  4. warwound

    warwound Expert Licensed User

    Look at the GoogleMapsExtras InfowindowAdapter to customize the infowindow.

    Martin.

    Sent from my GT-I9300 using Tapatalk 2
     
  5. cristianos

    cristianos Member Licensed User

    thanks ... I tried .. but I can not get the desired effect.
    Probably wrong ...

    Code:
    Sub InfoWindowAdapter1_GetInfoWindow(Marker1 As MarkerAs View
       
    '   the default InfoWindow will be used if this event Sub is not defined or if it returns Null
       Log("InfoWindowAdapter1_GetInfoWindow")
       
    'Dim InfoWindowLabel As Label
       'InfoWindowLabel.Initialize("")
       'InfoWindowLabel.Color=Colors.Red
       'InfoWindowLabel.TextColor=Colors.White
       'InfoWindowLabel.Initialize("")
       
       
    Dim InfoWindowPanel As Panel
       InfoWindowPanel.Initialize(
    "")
       InfoWindowPanel.Color = 
    Colors.Gray
       
       
    Dim PicLocal As ImageView
       PicLocal.Initialize(
    "")
       PicLocal.Bitmap = 
    LoadBitmap(File.DirAssets,"map_marker_32.png")
       PicLocal.BringToFront
       
       
       MapPanel.AddView(InfoWindowPanel, 
    0,0,150dip,80dip)
       InfoWindowPanel.AddView(PicLocal,
    10,10,40,40)
       
       
    'InfoWindowLabel.Text=Marker1.Title&CRLF&Marker1.Snippet
       Return InfoWindowPanel
    End Sub
     
  6. warwound

    warwound Expert Licensed User

    Here's an example of using the InfoWindowAdapter:

    Code:
    Sub Process_Globals
    End Sub

    Sub Globals
       
    Dim ContainerPanel As Panel
        
    Dim GoogleMap1 As GoogleMap
       
    Dim InfoWindowPanel As Panel
        
    Dim MapFragment1 As MapFragment
        
    Dim MapPanel As Panel
       
    Dim Markers As Map
       
    Dim SnippetLabel As Label
       
    Dim ThumbImage As ImageView
       
    Dim TitleLabel As Label
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
       
    Activity.LoadLayout("Main")
        
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
            
    ToastMessageShow("Google Play services not available."True)
        
    Else
            MapFragment1.Initialize(
    "MapFragment1", MapPanel)
        
    End If 
    End Sub

    Sub MapFragment1_Ready
        
    Log("MapFragment1_Ready")
        GoogleMap1 = MapFragment1.GetMap
        
    If GoogleMap1.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map."True)
        
    Else
          
    Dim GoogleMapsExtras1 As GoogleMapsExtras
          
    Dim InfoWindowAdapter1 As InfoWindowAdapter
          
          InfoWindowAdapter1.Initialize(
    "InfoWindowAdapter1")
          GoogleMapsExtras1.SetInfoWindowAdapter(GoogleMap1, InfoWindowAdapter1)
          
          InfoWindowPanel.Initialize(
    "")
          InfoWindowPanel.LoadLayout(
    "InfoWindow")
          
    '    a hack(ish) way to set InfoWindowPanel width and height!
          MapPanel.AddView(InfoWindowPanel, 00280dip120dip)
          InfoWindowPanel.RemoveView
          
          Markers.Initialize
          
          
    Dim Marker1 As Marker
            Marker1=GoogleMap1.AddMarker(
    52.756190.3980"Home Sweet Home")
          Marker1.Snippet=
    "Home is where the heart is!"
          Markers.Put(Marker1, Marker1)
          
          
    Dim Marker1 As Marker
            Marker1=GoogleMap1.AddMarker(
    52.935140.4829"Hunstanton")
          Marker1.Snippet=
    "A charming seaside town. Popular with the tourists."
          Markers.Put(Marker1, Marker1)
          
            
    Dim CameraPosition1 As CameraPosition
            CameraPosition1.Initialize(
    52.756190.39808)
            GoogleMap1.AnimateCamera(CameraPosition1)
        
    End If
    End Sub

    Sub InfoWindowAdapter1_GetInfoContents(Marker1 As MarkerAs View

       
    '   Return Null
       
       
    '   the default InfoContent will be used if this event Sub is not defined or if it returns Null
       Log("InfoWindowAdapter1_GetInfoContents")
       
       TitleLabel.Text=Marker1.Title
       SnippetLabel.Text=Marker1.Snippet
       
    '   ThumbImage.Bitmap=?   how will you store the file path/file name of the image to display?
       '   it's a shame that the Marker object has no Tag property which could be used to store such info
       
       
    Return InfoWindowPanel
    End Sub
    Your posted code shows that you add tyour InfoWindowPanel to your MapPanel and then return from your Sub.
    In my code i do not add my InfoWindowPanel to any (parent) View in the GetInfoContents Sub.
    Though when my InfoWindowPanel is initially created i add it to the MapPanel - the InfoWindowPanel is now a fixed 280 x 120 dip in size.
    I remove the InfoWindowPanel from the MapPanel immediately - the user does not see the InfoWindowPanel.
    Now when GetInfoContents returns the InfoWindowPanel it is correctly sized.
    Without this hack the infowindow was sizing itself to be full screen.

    You can download this example from http://android.martinpearman.co.uk/b4a/temp/CustomInfoWindow.zip.

    Martin.
     
    DonManfred and toby like this.
  7. systems1

    systems1 Member Licensed User

    I downloaded this example,

    When i run this example it shows a blank page. why this happen?

    Thanks
     

    Attached Files:

  8. warwound

    warwound Expert Licensed User

    I'd guess you haven't changed the private sign key in my demo project?
    You need to create a private sign key on your computer to match the demo package name etc.
    Or transplant the code from the demo into a b4a project that already has a working private sign key.

    Martin.
     
  9. systems1

    systems1 Member Licensed User

    Ok thanks for the information,
    But if my code have a click event for the marker, the popup is not working.
    Code:
    Sub MapFragment1_MarkerClick (SelectedMarker As MarkerAs Boolean
        
    Log(SelectedMarker.Position.Latitude)
        
    Return True
    End Sub
    How can i get the click event of marker ?

    Thanks
     
  10. warwound

    warwound Expert Licensed User

    Your Sub MapFragment1_MarkerClick returns True.
    This tells the library that your Sub has handled the Marker click therefore the library takes no further action - it doesn't open the InfoWindow.

    If you change your Sub so that it returns False then you should see the InfoWindow.

    Martin.
     
  11. Dario126

    Dario126 Member Licensed User

    I see that You have some button "detail" on infowindow.

    How do You get click event on that button?

    I have tried to generate click event (through abstract designer) for button, but it thus not react - it thus not generate event. When user clicks on infowindow inside button, only complete infowindow "shows" focus, and no other control can get focus.


    Also I tried to put webview component on infowindow and load string on to it (MyWebView.LoadHtml("test")), but nothing shows on it. Other components receive my changes of text (label.text and similar) but no WebView. I probably missing something. Do yuo have some working example about this?
     
  12. warwound

    warwound Expert Licensed User

    Take a look here: https://developers.google.com/maps/documentation/android/infowindows:
    So what you see as the contents of the infowindow is an image generated from all of the Views that make up the infowindow.
    It's not a View containing other Views where each View has the usual click and touch detection listeners :(.

    You can detect a click on the entire infowindow itself but that's all you can do.

    I think that an image cannot be generated from a WebView until the WebView has:
    • Been added to the Activity layout and has dimensions - it has Width and Height greater than 0.
    • Fully loaded and rendered a webpage.

    Adding a WebView to a custom infowindow means that neither of these two conditions have been satisfied when the GoogleMaps library tries to get an image of the WebView - so you don't see anything in your custom infowindow.

    Your only solution is to display your interactive custom infowindow contents within a standard View such as a Panel and not an infowindow.

    There's an interesting post on Stackoveflow here: http://stackoverflow.com/questions/...riginal-android-google-maps/15040761#15040761.
    You can see the proposed solutions are far from straightforward and all involve a need to use java.

    Martin.
     
    Dario126 likes this.
  13. Dario126

    Dario126 Member Licensed User

    Thank you Martin.. your answer makes me sad, but it's very clear diagnose. Webview I want to use only because HTML formatting, so maybe I'll try to load it somewhere else and create bitmap from it, then load it into infowindow. Interactivity with buttons and other stuff I will put somewhere else, not in infowindow ..

    I hope You get some good compensation from Basic4Android 'company', because without support of you and few others like you, basic4android is not even half as good when someone tries something more then basic stuff.
     
    warwound likes this.
  14. Dario126

    Dario126 Member Licensed User

    Why do I get this error
    on this code
    Code:
    Sub Map_Ready

        gMap = mFragment.GetMap
     
        
    If gMap.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map"True)

        
    Else
       
            gMap.MyLocationEnabled=
    True   
            gMap.GetUiSettings.ZoomControlsEnabled=
    False
            gMap.GetUiSettings.MyLocationButtonEnabled=
    False
           
            
    'INFO WINDOW ADAPTER
            Dim InfoWindowAdapter1 As InfoWindowAdapter
            InfoWindowAdapter1.Initialize(
    "InfoWindowAdapter1")
              gXtra.SetInfoWindowAdapter(gMap, InfoWindowAdapter1)   
              InfoWindowPanel.Initialize(
    "")
              InfoWindowPanel.LoadLayout(
    "Layout_InfoWindowPanel")
              pnlMap.AddView(InfoWindowPanel, 
    00170dip65dip)
              InfoWindowPanel.RemoveView       
           
            
    'MAP PADDING
    '        gXtra.SetPadding(gMap, 0, 80, 0, 0)
           
            
    Dim icl As OnInfoWindowClickListener
            icl.Initialize(
    "InfoWindowClick")
            gXtra.SetOnInfoWindowClickListener(gMap, icl)  
    ' == THIS LINE GENERATES ERROR ABOVE
                 
        
    End If

    End Sub


    Sub InfoWindowClick(Marker As Marker)
        
    Log("InfoWindowClick")
    End Sub


    Also I have problem with this line
    Code:
    'MAP PADDING
            gXtra.SetPadding(gMap, 08000)
    which gives this error
     
  15. warwound

    warwound Expert Licensed User

    If you look in the log you'll probably see an entry such as:

    OnInfoWindowClickListener not initialized, no event handling Sub found

    You've initialized the OnInfoWindowClickListener with the event name "InfoWindowClick" and the OnInfoWindowClickListener raises the event "Click".
    So you need a sub such as:

    Code:
    Sub InfoWindowClick_Click(Marker As Marker)
      
    Log("InfoWindowClick_Click")
    End Sub
    Your second problem is i'd guess because you're using the rapid debug mode?
    And presumably everything works fine when compiling with other modes?

    This has been reported quite often on the forum - both libraries GoogleMaps and GoogleMapsExtras sometimes cause this problem in rapid debug mode.

    Erel has an explanation here: http://www.basic4ppc.com/android/fo...android-v2-tutorial.24415/page-19#post-220525, there is no fix or workaround unfortunately.

    If rapid debug mode isn't the problem then maybe your Google Play Services library is not up to date, the setPadding method was added to the android GoogleMaps library in Sept 2013: https://developers.google.com/maps/documentation/android/releases#september_2013.

    Use the Android SDK Manager to check you have the latest version of the Google Play Services library and be sure to copy the latest version from the SDK folder to your b4a additional libraries folder.
    The SDK folder that contains the Google Play Services library is:

    <android-sdk-location>/extras/google/google_play_services/libproject/google-play-services_lib/libs

    Martin.
     
    Dario126 likes this.
  16. Dario126

    Dario126 Member Licensed User

    Thank you again Martin. Both of your pointers helped.
    In second problem, I did have new version of Google Play services, but only in original folder, and I forget that I must copy it to b4a library folder :=(

    Btw. as soon I start make some real money, I'll will follow up on your signature line ;=)
     
    warwound likes this.
  17. fasilosman

    fasilosman Active Member Licensed User

  18. warwound

    warwound Expert Licensed User

  19. fasilosman

    fasilosman Active Member Licensed User

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