Android Question Add Image in Infowindow Marker Maps from server

Discussion in 'Android Questions' started by juniorteacher, May 15, 2018.

  1. juniorteacher

    juniorteacher Member Licensed User

    only last image in my server,shown in all marker (should be different)
    i use imagedownloader

    Code:
    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
        Private VP As AHViewPager
        
    Private ToolBar As ACToolBarLight
        
    Private NavDrawer As DSNavigationDrawer
        
    Private Switch As ACSwitch
        
    Dim closeCntr As Int= 0
        
    Private Label1 As Label
        
    Private Label2 As Label
        
    Dim datatanaman As HttpJob

        
    Private MapFragment1 As MapFragment
        
    Private gmap As GoogleMap
        
    Private ListView1 As CustomListView
        
    Dim long1(1000),lat1(1000As Float
        
    Dim totaldata,closeCntr As Int
        
    Dim m2(1000As Marker
        
    Dim MapPanel As Panel
        
    Dim InfoWindowPanel As Panel
        
    Private TitleLabel As Label
        
    Private SnippetLabel As Label
        
    Private ThumbImage As ImageView
        
    Private ContainerPanel As Panel
        
    Dim m As Map
       
        
    Private ImageView1 As ImageView
    End Sub


    Sub Activity_Create(FirstTime As Boolean)
        
    Dim xml As XmlLayoutBuilder
        
    'Do not forget to load the layout file created with the visual designer. For example:
        NavDrawer.Initialize2("NavDrawer"Activity, NavDrawer.DefaultDrawerWidth, NavDrawer.GRAVITY_START)
        
    Activity.LoadLayout("layout3")
        NavDrawer.InitDrawerToggle
        NavDrawer.NavigationView.LoadLayout( 
    "navheaderLayout.bal", NavDrawer.DefaultHeaderHeight)
        NavDrawer.NavigationView.Menu.AddWithGroup2(
    111"Home",  xml.GetDrawable("ic_home"))
        NavDrawer.NavigationView.Menu.AddWithGroup2(
    121"Data", xml.GetDrawable("ic_data"))
        NavDrawer.NavigationView.Menu.AddWithGroup2(
    131"Map",  xml.GetDrawable("ic_map")).Checked = True
        NavDrawer.NavigationView.Menu.AddWithGroup2(
    141"Logout",xml.GetDrawable("ic_logout"))
        ToolBar.InitMenuListener
        
    Switch.Initialize("")
        NavDrawer.NavigationView.Menu.SetGroupCheckable(
    1TrueTrue)
        Label1.Text = Main.nama1
        Label2.Text = Main.level1
        posttdatatanaman
        m.Initialize
        ToolBar.Title = 
    "Data Maps"
       
        
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
            
    ToastMessageShow("Please install Google Play Services."True)
       
        
    Else
            MapFragment1.Initialize(
    "MapFragment1", MapPanel)
        
    End If
       
    End Sub

    Sub MapFragment1_Ready
        
    'Log("MapFragment1_Ready")
        gmap = MapFragment1.GetMap
        
    If gmap.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map."True)
        
    Else
            
    Dim GoogleMapsExtras1 As GoogleMapsExtras
            
    Dim InfoWindowAdapter1 As InfoWindowAdapter
           
            InfoWindowAdapter1.Initialize(
    "InfoWindowAdapter1")
            GoogleMapsExtras1.SetInfoWindowAdapter(gmap, InfoWindowAdapter1)
           
            InfoWindowPanel.Initialize(
    "")
            InfoWindowPanel.LoadLayout(
    "InfoWindow")
            
    '     a hack(ish) way to set InfoWindowPanel width and height!
            MapPanel.AddView(InfoWindowPanel, 00280dip120dip)
            InfoWindowPanel.RemoveView
        
    End If
    End Sub

    Sub InfoWindowAdapter1_GetInfoContents(Marker1 As MarkerAs View
        
    'Log("InfoWindowAdapter1_GetInfoContents")
        TitleLabel.Text=Marker1.Title
        SnippetLabel.Text=Marker1.Snippet
        
    Return InfoWindowPanel
    End Sub

    Sub Activity_Resume

    End Sub


    Sub Activity_Pause (UserClosed As Boolean)
        
    CallSub(ImageDownloader, "ActivityIsPaused")
    End Sub

    Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
       
        
    If KeyCode = KeyCodes.KEYCODE_BACK Then
            closeCntr = closeCntr + 
    1
            
    If closeCntr = 2 Then
                closeCntr = 
    0
                
    StartActivity(Main)
                
    Activity.Finish
            
    Else
                
    ToastMessageShow("Tekan 2 kali untuk Loguot"True)
                
    Return True
            
    End If
        
    End If
    End Sub



    Sub posttdatatanaman
        datatanaman.Initialize(
    "datatanaman",Me)
        datatanaman.PostString(
    "http://pertanian.tech/sqldata.php""key=" & Main.key1 & "&tipe=datatanaman"  )
        
    ProgressDialogShow("Loading Data Tanaman...")
    End Sub



    Sub JobDone (Job As HttpJob)
       
        
    If Job.Success = True Then
            
    Log(Job.JobName)
            
    Select Job.JobName
                
    Case "datatanaman"
                    
    'Log(Job.GetString)
                   
                    gmap = MapFragment1.GetMap
                    
    Dim cp As CameraPosition
                    cp.Initialize(-
    7.5859957112.87512)
                    gmap.AnimateCamera(cp)
                   
                   
                    
    Dim parser As JSONParser
                    parser.Initialize(Job.GetString)
                    
    Dim root As List = parser.NextArray
                    
    For Each colroot As Map In root
                        
    Dim no2 As Int = colroot.Get("no")
                        
    Dim keterangan2 As String = colroot.Get("keterangan")
                        
    Dim nama2 As String = colroot.Get("nama")
                        
    Dim foto2 As String = colroot.Get("foto")
                        
    Dim id2 As Int = colroot.Get("id")
                        
    Dim id2_user As String = colroot.Get("id_user")
                        
    Dim lat2 As String = colroot.Get("lat")
                        
    Dim long2 As String = colroot.Get("long")
                        
    'clv1.AddTextItem(nama2,id2)
                        ProgressDialogHide
                       
    If (lat2 <> NullOr (long2 <> NullThen
                            lat1(id2) = lat2
                            long1(id2)= long2
                            m2(id2)=gmap.AddMarker(lat1(id2), long1(id2),nama2)
                            m2(id2).Snippet=keterangan2
                            m.Put(ImageView1,
    "https://pertanian.tech/datagambar/uploads/" & foto2)
                            CallSubDelayed2(ImageDownloader, 
    "Download", m)
                            
    'm2(id2).Put(Marker1, Marker1)
                            'm2(id2) = gmap.AddMarker(lat1(id2), long1(id2),nama2 & " # " & keterangan2)

                    
    End If
                    
    Next
                       
       
            
    End Select
        
    Else
            
    Log("Error: " & Job.ErrorMessage)
            
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
        
    End If
        Job.Release
    End Sub


    #Region Navdrawer Events
    Sub NavDrawer_DrawerClosed (DrawerGravity As Int)

    End Sub

    Sub NavDrawer_DrawerOpened (DrawerGravity As Int)

    End Sub

    Sub NavDrawer_DrawerSlide (Position As Float, DrawerGravity As Int)

    End Sub


    Sub NavDrawer_NavigationItemSelected (MenuItem As ACMenuItem, DrawerGravity As Int)
        
    'LogColor("NavItem selected: " & MenuItem.Title, Colors.Green)
        Select MenuItem.Id
            
    Case 1 'Hone
                StartActivity(Dashboard)
                
    Activity.Finish
            
    Case 2 'Data
                StartActivity(Data)
                
    Activity.Finish
            
    Case 3 'Map
               
               
            
    Case 4 'Setting
                StartActivity(Main)
                
    Activity.Finish
        
    End Select
        NavDrawer.NavigationView.CheckedItem = 
    MenuItem.Id
        NavDrawer.CloseDrawer2(DrawerGravity)
    End Sub
    #End Region

    #Region ToolBar Events
    Sub Toolbar_NavigationItemClick
        
    If NavDrawer.IsDrawerOpen Then
            NavDrawer.CloseDrawer
        
    Else
            NavDrawer.OpenDrawer
        
    End If
    End Sub
    #End Region
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    There is no reason to use ImageDownloader. It will be simpler to use Wait For to download each image and then set it to the marker.

    [B4X] OkHttpUtils2 with Wait For
     
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