iOS Question GoogleMap Extras help (SOLVED)

walterf25

Expert
Licensed User
Longtime User
Hello, i am trying to accomplish a similar effect to what i have done in one of my apps in B4A, I know there is a class Erel wrote for googleMapsExtras but i'm not too sure how to use it yet, below is the code i've written in B4A which accomplishes what i'm trying to do in B4i, i've also attached an image of the animation just so you guys can get a better idea of what it is i'm trying to do.
312bnk0.gif


Here is the code i've used in B4A

B4X:
Sub MapFragment1_Ready
    map = MapFragment1.GetMap
    map.MyLocationEnabled = True
    Dim googlemapsextra As GoogleMapsExtras
    
   ''this is where the marker locations are being added to be used later below to calculate the bounds so that the map can center all the markers added.
    Dim LatLngBoundsBuilder1 As LatLngBoundsBuilder
    LatLngBoundsBuilder1.Initialize
    markers.Initialize
    
    If common.objectlist.Size > 0 Then
        For i = 0 To common.objectlist.Size - 1
            Dim data As NearByData
            Log("objectlist: " & i & " " & common.objectlist.Get(i))
            data.Initialize
            data = common.objectlist.Get(i)
            LogColor("location added: " & data.Lat & " " & data.Lon, Colors.Red)
            Dim m1 As Marker = map.AddMarker(data.Lat, data.Lon, data.Bus_Number)
            m1.Snippet = data.Title & CRLF & "Bus Stop# " & data.Tag
           ''adding markers to the LatLngBoundsBuilder
            LatLngBoundsBuilder1.Include(m1.Position)
            markers.Put(m1, m1)
            Dim p As B4XView = xui.CreatePanel("")
            p.SetLayoutAnimated(0, 0, 0, clv.AsView.Width, 75dip)
            clv.Add(p, data)
        Next
        
        Dim InfoWindowAdapter1 As InfoWindowAdapter
      
        InfoWindowAdapter1.Initialize("InfoWindowAdapter1")
        googlemapsextra.SetInfoWindowAdapter(map, InfoWindowAdapter1)
        
        infowindow.Initialize("")
        infowindow.SetLayoutAnimated(0,0,0,230dip,120dip)
        infowindow.LoadLayout("InfoWindow")
        
       ''hackish way to add custom infowindow with custom size
        pnlmapfragment.AddView(infowindow, 0, 0, 230dip, 120dip)
        infowindow.RemoveView
        
        
        Dim MarkerBounds As LatLngBounds=LatLngBoundsBuilder1.Build
        Dim camupdate As CameraUpdate
        Dim camfactory As CameraUpdateFactory
        camupdate = camfactory.NewLatLngBounds2(MarkerBounds, 100%x, pnlmapfragment.Height, 128)
        googlemapsextra.AnimateCamera(map, camupdate)
    End If
End Sub

Any ideas, i'd really appreciate it any advice or hints to help me accomplish a similar effect.

Thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User
Start with running the example: https://www.b4x.com/android/forum/threads/class-googlemapsextra.56871/

Which feature is missing from GoogleMapsExtra?
Hi @Erel I did take a look at the Example you are referring to, however i don't see the
LatLngBoundsBuilder method, if you notice in my code inside the for loop each marker position is added to the LatLngBoundsBuilder
B4X:
LatLngBoundsBuilder1.Include(m1.Position)
Then the LatLngBoundsBuilder is built and passed to the MarkerBounds which is used by the Camera object to calculate and center the Markers added to the map.

Is there a way to do the same with your GoogleMapsExtra class?

Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Start with running the example: https://www.b4x.com/android/forum/threads/class-googlemapsextra.56871/

Which feature is missing from GoogleMapsExtra?
Found this by searching on another forum, my knowledge of Objective C is zero, how would I be able to turn the following code into B4i?

B4X:
''Before start the placing the markers:
var bounds = GMSCoordinateBounds.alloc().init();

''While placing the markers (in the loop):
bounds = bounds.includingCoordinate(marker[i].position);
''After placing the markers:
var update = GMSCameraUpdate.fitBoundsWithPadding(bounds, padding); mapView.gMap.moveCamera(update);

Thanks,
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Upvote 0

walterf25

Expert
Licensed User
Longtime User
This is what the code looks like and it works, except that I don't see the same animation as in the image in my first post, but this will do just fine.
B4X:
    If common.objectlist.Size > 0 Then
    For i = 0 To common.objectlist.Size - 1
        Dim data As NearByData
        Log("objectlist: " & i & " " & common.objectlist.Get(i))
        data.Initialize
        data = common.objectlist.Get(i)
        LogColor("location added: " & data.Lat & " " & data.Lon, Colors.Red)
        Dim m1 As Marker = gmap.AddMarker(data.Lat, data.Lon, data.Bus_Number)
        m1.Snippet = data.Title & CRLF & "Bus Stop# " & data.Tag
               '''add marker positions to list
        points.Add(m1.Position)
        ''LatLngBoundsBuilder1.Include(m1.Position)
            
        gextra.SetGroundAnchor(m1, 0.5, 0.5)
        markers.Put(m1, m1)
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, clv.AsView.Width, 50dip)
        clv.Add(p, data)
    Next
    End If
    
       ''will center around the markers added
    gextra.ZoomToPoints(points)

Thanks
Walter
 
Upvote 0
Top