iOS Question GoogleMapsExtra.ZoomToPoints() Problem - [Worked Around]

RichardN

Well-Known Member
Licensed User
Longtime User
I have a multi-purpose module that displays from one to many points on a Google Map. The points are derived from an SQLite database. The Lat/Long positions are assigned to a list which is later used as the basis for GoogleMapsExtra.ZoomToPoints(ListOfPoints). The expected number of map markers are plotted correctly every time, however there is a problem with zooming to the area containing the list of points...

When the module is first called (initialized) it does not zoom as expected. Instead of framing the points in the list I get a whole-world view. However when the module is next called the zoom works perfectly every time.

I have tried rearranging the code differently and even calling ZoomToPoints with CallSubDelayed2 but with no success. Have I made a schoolboy error?

ShowMap Module:
Sub Process_Globals

    Private PageShowAirfieldsMap As Page
    Private gMap As GoogleMap
    Private gMapsExtra As GoogleMapsExtra
        
End Sub

Public Sub Show(Query As String,Graphic As String, Lat As Double,Lon as Double)
    
    If PageShowAirfieldsMap.IsInitialized = False Then
        
        PageShowAirfieldsMap.Initialize("PageShowAirfieldsMap")
        gMap.Initialize("gMap", Main.APIkey)
        gMapsExtra.Initialize(gMap)
        PageShowAirfieldsMap.RootPanel.AddView(gMap,0,0,100%x,100%y)
    
    End If

    Dim Bm As Bitmap = LoadBitmapResize(File.DirAssets,Graphic,30,30,True)
    
    gMap.Clear
    Main.NavControl.ShowPage(PageShowAirfieldsMap)
    
    Private Locations As ResultSet
    Locations = Main.SQL.ExecQuery(Query)
    
    Dim ThisLat, ThisLong As Double
    
    Dim Points As List
    Points.Initialize
    
    Do While Locations.NextRow
        
        ThisLat = Locations.GetDouble("Lat")
        ThisLong = Locations.GetDouble("Long")
        Dim ThisPosition As LatLng
        ThisPosition.Initialize(ThisLat,ThisLong)
        Points.Add(ThisPosition)

        gMap.AddMarker3(ThisLat,ThisLong, Locations.GetString("Name"),Bm)
        
    Loop   
    

    If Points.Size = 1 Then                    'Deal with the zoom
    
        Dim cpos As CameraPosition
        cpos.Initialize(Lat,Lon,14)            'Frame a single location only - Zoom 14
        gMap.AnimateCamera(cpos)

    Else
        
        gMapsExtra.ZoomToPoints(Points)        'Frame multiple positions
                                               'Only works after 2nd & subsequent page calls
    End If
            
End Sub
 

Semen Matusovskiy

Well-Known Member
Licensed User
Guess, you need to change a logic. Using one point can't set scale factor by definition.
When there is one pont only you can add current location as second point and to use the same ZoomToPoints.
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
When the Points.Size = 1 the bounds/zoom is explicitly generated using a single Lat/Long position using the CameraPosition and AnimateCamera method:
B4X:
If Points.Size = 1 Then                      'Deal with the zoom
        
    Dim cpos As CameraPosition
        cpos.Initialize(Lat,Lon,14)            'Frame a single location only - Zoom 14
        gMap.AnimateCamera(cpos)
    Else
        gMapsExtra.ZoomToPoints(Points)        'Frame multiple positions
                                               'Only works after 2nd & subsequent page calls
End If

Quite why the gMapsExtra.ZoomToPoints only functions on 2nd and subsequent calls of Page.Show() remains a mystery. I thought perhaps it needed to be executed after the delayed initialisation of the Google Map but unlike Android, iGoogleMaps has no GoogleMap_Ready event to test the theory.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Where did you read that AnimateCamera changes zoom (scale) ? It moves the camera to the new position. Nothing more.
Imagine, you talk to GoogleMaps - show me a city Rome. But how GoogleMaps will understand, what do you want see - a map of Italy, a map of Europe or World map ?
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
CameraPosition is a 3D object holding the values: Latitude As Double, Longitude As Double, ZoomValue As Float

B4X:
Dim Cpos As CameraPosition
Cpos.Initialize(Latitude,Longitude, ZoomValue)
gMap.AnimateCamera(Cpos)

But of course that was not the question I was asking....
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
As I was only using the ZoomToPoints function of GoogleMapsExtra I removed the entire GMX module and copied only the relevant code to the module in question.... Unfortunately I got the same result.

In the end I got so fed up trying to make it work I devised a work-around. The Page in question is called when the App starts but is passed an AbortFlag variable. The code aborts at the end of the initialisation and before the page is made visible.... Therefore the problem that occurs on first-call never arises.

Not a very pretty solution but it has the desired result. There appears to be an inconsistency with the behaviour of the NormalObject code in GMX
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Well I tested your initial code (with small modifications) and noticed nothing unusual. To run it, enter API key and add GoogleMaps bundle in Files\Special.
I thought that maybe a problem in bundle release. I use old Google Maps SDK for iOS version: 2.2.30010.0
 

Attachments

  • s11.zip
    4.7 KB · Views: 207
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Thanks Semen.... I cannot identify my Google release bundle as any specific version but the files are the same and have the same date/time stamp as yours so I presume they are fine.

Your code functions perfectly here. My code is part of a much larger project and I have no other problems with it so I will stick with the work-around and not waste any more time on it.
 
Upvote 0
Top