Android Question Add Image in Infowindow Marker Maps from server

juniorteacher

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

B4X:
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(1000) As Float
    Dim totaldata,closeCntr As Int
    Dim m2(1000) As 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(1, 1, 1, "Home",  xml.GetDrawable("ic_home"))
    NavDrawer.NavigationView.Menu.AddWithGroup2(1, 2, 1, "Data", xml.GetDrawable("ic_data"))
    NavDrawer.NavigationView.Menu.AddWithGroup2(1, 3, 1, "Map",  xml.GetDrawable("ic_map")).Checked = True
    NavDrawer.NavigationView.Menu.AddWithGroup2(1, 4, 1, "Logout",xml.GetDrawable("ic_logout"))
    ToolBar.InitMenuListener
    Switch.Initialize("")
    NavDrawer.NavigationView.Menu.SetGroupCheckable(1, True, True)
    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, 0, 0, 280dip, 120dip)
        InfoWindowPanel.RemoveView
    End If
End Sub

Sub InfoWindowAdapter1_GetInfoContents(Marker1 As Marker) As 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.5859957, 112.875, 12)
                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 <> Null) Or (long2 <> Null) Then
                        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
 
Top