iOS Question Issue with Google Maps Camera Position in 1:1 Panel

ykucuk

Well-Known Member
Licensed User
Longtime User
Hello,

I'm encountering an issue with Google Maps in my application. When I use Google Maps in full screen mode, the camera position works correctly. However, when I place the map inside a 1:1 aspect ratio panel, the camera position does not focus as expected.


Works well
B4X:
gmap.Initialize("gmap", ApiKey)
Root.AddView(gmap, 0,0,GetDeviceLayoutValues.Width,GetDeviceLayoutValues.Height)

Position is wrong
B4X:
gmap.Initialize("gmap", ApiKey)
pnl.AddView(gmap, 0, 0, pnl.Width,pnl.Width)


Despite setting the camera position , it doesn't focus correctly when the map is placed in the 1:1 panel. Any suggestions on how to resolve this issue would be greatly appreciated.

Thank you!
 

Attachments

  • sim1.jpg
    sim1.jpg
    272 KB · Views: 19
  • Sim2.jpg
    Sim2.jpg
    261.2 KB · Views: 19

ykucuk

Well-Known Member
Licensed User
Longtime User
Are you resizing the map when the page is resized?

Yes

Hello Erel,

In the example project, I set the height of the Panel to %100X via the designer. While adding the gmap inside Addmap, I used these dimensions. I made the camera position the same as the markers I added to the map, but the problem persists.


B4X:
Private Sub AddMap
    gmap.Initialize("gmap", ApiKey)
    Panel1.AddView(gmap, 0, 0, Panel1.Width, Panel1.Height)
    'gmap.MapType = gmap.MAP_TYPE_TERRAIN
    gmap.GetUiSettings.CompassEnabled = True
    gmap.GetUiSettings.MyLocationButtonEnabled = True
    gmap.MyLocationEnabled = True
    'add three markers
    Dim m As Marker = gmap.AddMarker(41.01, 28.01, "test")
    m.Snippet = "Marker 1"
    m.Opacity = 0.5
    m = gmap.AddMarker2(41, 28, "Marker 2", Colors.Green)
'    gmap.AddMarker3(30, 30, "marker3", LoadBitmap(File.DirAssets, "up76.png"))
    gmap.AddMarker3(41.011, 28.011, "marker3", CreateBitmap("L1"))
    gextra.Initialize(gmap)
    gextra.SetGroundAnchor(m, 0.5, 0.5)  
    'gextra.MapStyle(File.ReadString(File.DirAssets, "style.json"))
    Dim no As NativeObject = gmap
    no.SetField("selectedMarker", m)
    m.Draggable = True
    'gmap.AddMarker3(20, 20, "ddd", LoadBitmap(File.DirAssets, "up76.png"))
'    'change the camera position
    Dim c As CameraPosition
    c.Initialize2(41, 28, 14, 315, 45)
    gmap.AnimateCamera(c)
    gextra.SetMarkerRotation(m, 45)
    Dim ne, sw As LatLng
    ne.Initialize(20, 20)
    sw.Initialize(00, 00)
    Dim bounds As Object = gextra.CreateBounds(ne, sw)
    gextra.AddGroundOverlay(bounds, LoadBitmap(File.DirAssets, "up76_2.png"))
    gextra.SetSelectedMarker(m)
''    'add a polyline
    pl = gmap.AddPolyline
    Dim l1, l2, l3, l4 As LatLng
    l1.Initialize(10, 10)
    l2.Initialize(10, 20)
    l3.Initialize(20, 20)
    l4.Initialize(20, 10)
    'pl.Points = Array(l1, l2, l3, l4, l1)
    'gextra.ZoomToPoints(pl.Points)
    pl.Width = 5
    pl.Color = Colors.Red
    gextra.AddPolygon(Array(l1, l2, l3, l4, l1), 0x800000FF, Colors.Gray)
End Sub
You can download the example project from the following link:

example project
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The mistake is here:
B4X:
Private Sub Page_Resize (Width As Float, Height As Float)
    If gmap.IsInitialized Then gmap.SetLayoutAnimated(0, 1, 0, 0, Width, Height)
End Sub
You are resizing the map to the page size.

Best to handle the panel resize event instead:
B4X:
Private Sub Panel1_Resize (Width As Float, Height As Float)
    If gmap.IsInitialized Then gmap.SetLayoutAnimated(0, 1, 0, 0, Width, Height)
End Sub
 
Upvote 0
Top