Android Question GoogleMapsExtra Problem [Solved]

RichardN

Well-Known Member
Licensed User
Longtime User
I am struggling to understand the use of AnimateToBounds and AnimateCamera when using GoogleMapsExtra. As you can see from the code I want to position the map to show the collection of waypoints added, also position the camera centrally in this described area. My (failed) code looks something like this:

B4X:
Dim LLboundsBuilder1 As LatLngBoundsBuilder
LLboundsBuilder1.Initialize
Dim ThisLL As LatLng
           
        Do While Locations.NextRow
           
            ThisLL.Initialize(Locations.GetDouble("Lat"),Locations.GetDouble("Long"))
            gMap.AddMarker3(ThisLL.Latitude,ThisLL.Longitude,Locations.GetString("Name"),bmpMyMarker)
            LLboundsBuilder1.Include(ThisLL)
           
        Loop
       
Dim Bounds As LatLngBounds = LLboundsBuilder1.Build      
gmx.AnimateToBounds(gMap,Bounds,5)                                                     '<<< Error here
          
Dim CameraUpdateFactory1 As CameraUpdateFactory
Dim CamUpdate As CameraUpdate
       
CamUpdate = CameraUpdateFactory1.NewLatLngBounds(Bounds,10 )
gmx.AnimateCamera(gMap,CamUpdate)

The log is not altogether informative:
com.google.maps.api.android.lib6.common.apiexception.c: Error using newLatLngBounds(LatLngBounds, int): Map size can't be 0. Most likely, layout has not yet occured for the map view. Either wait until layout has occurred or use newLatLngBounds(LatLngBounds, int, int, int) which allows you to specify the map's dimensions......

Unfortunately I can't get past the error line marked. Any advice?
 

DonManfred

Expert
Licensed User
Longtime User
Do While Locations.NextRow ThisLL.Initialize(Locations.GetDouble("Lat"),Locations.GetDouble("Long")) gMap.AddMarker3(ThisLL.Latitude,ThisLL.Longitude,Locations.GetString("Name"),bmpMyMarker) LLboundsBuilder1.Include(ThisLL) Loop
add some log here to see if there are any loops running. Based on the error i would say the list/resultset is empty
Dim ThisLL As LatLng
move this inside the loop too
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Thanks for the suggestions DonManfred but this does not fix the issue.

- Moving 'Dim ThisLL As LatLng' inside the loop has no effect on the error
- A log of ThisLL.Latitude shows the variable is being repeatedly populated.

- Same error
 
Last edited:
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
This has been extremely frustrating, particularly as my original code was 99% of the way to a solution. How is the programmer supposed to know what evidently benign processes need to run outside the normal run of code? Often searching this forum is neither easy or productive.... and English is my first language!

The problem in the code is that the Google Map object is not entirely complete in memory until the plotting code has completed, and by a long process of elimination that appears to be the case here. The code below now works fine. Utilising CallSubDelayed fixes that:

B4X:
Sub
        
    Dim Locations As ResultSet

    Locations = SQL.ExecQuery(Query)
            
    Dim LLboundsBuilder1 As LatLngBoundsBuilder
    LLboundsBuilder1.Initialize
            
    Do While Locations.NextRow
            
       Dim ThisLL As LatLng
       ThisLL.Initialize(Locations.GetDouble("Lat"),Locations.GetDouble("Long"))
       gMap.AddMarker3(ThisLL.Latitude,ThisLL.Longitude,Locations.GetString("Name"),Bm)
       LLboundsBuilder1.Include(ThisLL)
            
    Loop
        
    Dim Bounds As LatLngBounds = LLboundsBuilder1.Build     
    CallSubDelayed2(Me,"ZoomToBounds",Bounds)
                      
End Sub


Sub ZoomToBounds(LLbounds As LatLngBounds)

    gmx.AnimateToBounds(gMap,LLbounds,100)                       

End Sub
 
Upvote 0

Andris

Active Member
Licensed User
Longtime User
This has been extremely frustrating, particularly as my original code was 99% of the way to a solution. How is the programmer supposed to know what evidently benign processes need to run outside the normal run of code? Often searching this forum is neither easy or productive.... and English is my first language!
Thanks for your work on this Richard. It has saved some time for me. The forum becomes increasingly more valuable with every post like yours, describing solutions to problems. How is the programmer to know? By reading your answer. So you answered your own question ...
 
Upvote 0
Top