Android Question GoogleMaps - Error on loading map

Declan

Well-Known Member
Licensed User
Longtime User
I have the following error that I cannot understand (I have commented the errors in the "Sub loadMap(mapTrans As Map)"

My Code:
B4X:
Sub Globals
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
    Private btnClose As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Map")
    Wait For MapFragment1_Ready
    gmap = MapFragment1.GetMap
End Sub

Sub loadMap(mapTrans As Map)
    MapFragment1.GetMap.Clear'<---------ERROR: java.lang.RuntimeException: Object should first be initialized (GoogleMap).
    Dim cp As CameraPosition
    
    Dim cp As CameraPosition
    cp.Initialize(-25.856118,28.179312, 15)
    gmap.AnimateCamera(cp)'<-----------ERROR: java.lang.RuntimeException: Object should first be initialized (GoogleMap).
    
    Dim myMarker As String
    myMarker = mapTrans.Get(9) &" Voltage: " & mapTrans.Get(5) & "V" & " " & mapTrans.Get(8) & " KM" & " " & mapTrans.Get(7)
        
    gmap.AddMarker(mapTrans.Get(3), mapTrans.Get(4), myMarker)
        
    cp.Initialize(mapTrans.Get(3),mapTrans.Get(4), 15)
    gmap.AnimateCamera(cp)
    
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…