Android Question GoogleMaps : I'm loosing my mind with it!!!

Cableguy

Expert
Licensed User
Longtime User
Hi guys and gals.

I'm going crazy with how Gmaps is implemented, why??
In the designer we have props that we can't access by code, some, like the "visible" prop, can render the map un-usable... Iknow, "put the mapFragment inside a panel!", that is a redundant workaround, but it works, so... OK, BUT!!!!
We cannot use any "sleep" methods while the Map is not completly initializated/loaded... There is simply no way to know if MapFragment_Ready event is ever fired...

So, I am trying to acomplish something that should be simple, but its much more complicated than I would antecipate...
I want to load a "loading" screen while the Gmap initializes/loades and while I load all the markers in the database... but I just can't seem to make it work!!!!

Anyone else with similar frustrations??
 
Solution
sleep(0) before wait for gmap_Ready
This may break all types of wait for's, not just gmap. Wait for is used to catch an event. By using sleep in front of it, you allow event processing. This could lead to the event being fired before you wait for it and therefore you miss it and your wait for then just hangs there waiting for an event that already occurred.

TILogistic

Expert
Licensed User
Longtime User
?
B4X:
    Wait For gmap_Ready
    GoogleMap1 = Mapfragment1.GetMap
    If GoogleMap1.IsInitialized Then
        rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
        If Result Then
            GoogleMap1.MyLocationEnabled = True
            GoogleMap1.GetUiSettings.MyLocationButtonEnabled = True

see:
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
?
B4X:
    Wait For gmap_Ready
    GoogleMap1 = Mapfragment1.GetMap
    If GoogleMap1.IsInitialized Then
        rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
        If Result Then
            GoogleMap1.MyLocationEnabled = True
            GoogleMap1.GetUiSettings.MyLocationButtonEnabled = True

see:
I didn't say It didn't work! I said It doesn't work the way I intended it to work! Even if my logic is flowless!
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
??
We cannot use any "sleep" methods while the Map is not completly initializated/loaded... There is simply no way to know if MapFragment_Ready event is ever fired...

Wait For gmap_Ready
GoogleMap1 = Mapfragment1.GetMap
If GoogleMap1.IsInitialized Then
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
If Result Then
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Hi Omar,

I really hope you don't read me as disrespectfull, but my post was meant as a RANT about how inconsinstant the GMaps implementation is.

I can easily get it to work, but I can't get it to work along with other logic already implemented and working just fine.

Try to put a sleep(0) just before wait for MapFragment_ready and you will see that it just sits there... maybe a map is shown, but mylocation is never retrieved!
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
I use this to have my location

test;
B4X:
    Wait For gmap_Ready
    GoogleMap1 = Mapfragment1.GetMap
    If GoogleMap1.IsInitialized Then
        rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
        If Result Then
            GoogleMap1.MyLocationEnabled = True
            GoogleMap1.GetUiSettings.MyLocationButtonEnabled = True
            
            Dim OnMyLocationChangeListener1 As OnMyLocationChangeListener
            OnMyLocationChangeListener1.Initialize("OnMyLocationChangeListener1")
            GoogleMapsExtras1.SetOnMyLocationChangeListener(GoogleMap1, OnMyLocationChangeListener1)
            Wait For OnMyLocationChangeListener1_MyLocationChange(Location1 As Location)
            
            LastLocation = Location1

            Dim CameraPosition1 As CameraPosition = GoogleMap1.CameraPosition
            Dim NewCameraPosition As CameraPosition
            NewCameraPosition.Initialize2(LastLocation.Latitude, LastLocation.Longitude, 15, CameraPosition1.Bearing, CameraPosition1.Tilt)
            GoogleMap1.AnimateCamera(NewCameraPosition)
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I use this to have my location

test;
B4X:
    Wait For gmap_Ready
    GoogleMap1 = Mapfragment1.GetMap
    If GoogleMap1.IsInitialized Then
        rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
        Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
        If Result Then
            GoogleMap1.MyLocationEnabled = True
            GoogleMap1.GetUiSettings.MyLocationButtonEnabled = True
           
            Dim OnMyLocationChangeListener1 As OnMyLocationChangeListener
            OnMyLocationChangeListener1.Initialize("OnMyLocationChangeListener1")
            GoogleMapsExtras1.SetOnMyLocationChangeListener(GoogleMap1, OnMyLocationChangeListener1)
            Wait For OnMyLocationChangeListener1_MyLocationChange(Location1 As Location)
           
            LastLocation = Location1

            Dim CameraPosition1 As CameraPosition = GoogleMap1.CameraPosition
            Dim NewCameraPosition As CameraPosition
            NewCameraPosition.Initialize2(LastLocation.Latitude, LastLocation.Longitude, 15, CameraPosition1.Bearing, CameraPosition1.Tilt)
            GoogleMap1.AnimateCamera(NewCameraPosition)
Again, you are missing the point.... your code works, great... now put a sleep(0) before wait for gmap_Ready and you will see that it simply blocks the normal procedure of the code
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Its just an example... sleep(0) should not have any effect on the rest of the code, and yet, it blocks it...

In my logic attemps, I launched a "Loading" Screen, and started initializing/loading the map into a non-visible panel, and then Hide the "Loading" screen and show the map... But it simply doesn't want to work!!!
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
ok I understand.

you want to show a message that the map (tiles) is loading, and when it is ready you show it.

is it what you want??
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
see:
B4X:
    Dim OnMapLoadedCallback1 As OnMapLoadedCallback
    OnMapLoadedCallback1.Initialize("OnMapLoadedCallback1")
    GoogleMapsExtras1.SetOnMapLoadedCallback(GoogleMap1, OnMapLoadedCallback1)

B4X:
Sub OnMapLoadedCallback1_MapLoaded
    Log("OnMapLoadedCallback1_MapLoaded")
End Sub

ref.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
in my understanding, using the same logic other time controls (and languaje) do: sleep(0) = sleep(forever)
:D
In B4X DoEvents was deprecated ans Sleep(0) was to be used instead
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
Why don't put a panel over mapfragment with what you want. When map ready, change zorder to the panel under map and set invisible
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
sleep(0) before wait for gmap_Ready
This may break all types of wait for's, not just gmap. Wait for is used to catch an event. By using sleep in front of it, you allow event processing. This could lead to the event being fired before you wait for it and therefore you miss it and your wait for then just hangs there waiting for an event that already occurred.
 
Upvote 1
Solution
Top