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?
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