Per the code below, I am using a Wait For (per Erel's tutorial here) to wait until my Google Maps Fragment is ready, then moving to my current position. The checkForNewMessage sub is called from Activity_Resume.
The problem is that the Wait For in checkForNewMessage doesn't wait for the mapGMap_Ready callback to be fired, so the app crashes on the first line of gotoMyLocation because at that point gmap is not initialized. If I comment out the Wait For statement & uncomment the Do While loop under it, it works fine - which seems to confirm that the Wait For isn't working.
Is this a bug with Wait For, or am I missing something?
(gmap is a GoogleMap object declared in Globals & mapGMap is a MapFragment added to the layout in the designer)
- Colin.
The problem is that the Wait For in checkForNewMessage doesn't wait for the mapGMap_Ready callback to be fired, so the app crashes on the first line of gotoMyLocation because at that point gmap is not initialized. If I comment out the Wait For statement & uncomment the Do While loop under it, it works fine - which seems to confirm that the Wait For isn't working.
Is this a bug with Wait For, or am I missing something?
(gmap is a GoogleMap object declared in Globals & mapGMap is a MapFragment added to the layout in the designer)
B4X:
Private Sub checkForNewMessage
If Not(gmap.IsInitialized) Then
Wait For mapGMap_Ready
End If
Log("Map Fragment Ready")
' Do While Not(gmap.IsInitialized)
' Log("NOT INITIALIZED")
' Sleep(0)
' Loop
Private newIntent As Intent = Activity.GetStartingIntent
If newIntent.HasExtra("Notification_Tag") Then
If newIntent.GetExtra("Notification_Tag") = "notification-start" Then
updateMap(FirebaseMessaging.notificationMsg)
End If
Else
gotoMyLocation
End If
End Sub
Private Sub mapGMap_Ready
Log("GMAP READY")
gmap = mapGMap.GetMap
markerMap.Initialize
gmap.MyLocationEnabled = True
snippetClickListener.Initialize("InfoWindow")
gmapExtras.SetOnInfoWindowClickListener(gmap, snippetClickListener)
loadLocationRecords
Dim jo As JavaObject = gmap
Dim event As Object = jo.CreateEventFromUI("com.google.android.gms.maps.GoogleMap.OnInfoWindowLongClickListener", _
"InfoWindowLongClick", Null)
jo.RunMethod("setOnInfoWindowLongClickListener", Array(event))
End Sub
Private Sub gotoMyLocation
Do While Not(gmap.MyLocation.IsInitialized)
Log("My Location not initialized")
Sleep(0)
Loop
pos.Initialize(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, markerZoom)
gmap.AnimateCamera(pos)
End Sub
- Colin.
Last edited: