B4i Library [class]GoogleMapsExtra

Discussion in 'iOS Libraries' started by Erel, Aug 3, 2015.

  1. Erel

    Erel Administrator Staff Member Licensed User

    This class extends GoogleMaps library.
    Currently it supports:
    - AddCircle - Adds a circle at a give point.
    - AddGroundOverlay - Adds an image at the given bounds.
    - ZoomToPoints
    - SetSelectedMarker
    - SetMarkerRotation
    - SetGroundAnchor - sets the marker anchor.
    - AddPolygon


    Example:
    Code:
    gextra.Initialize(gmap)
    Dim ne, sw As LatLng
    ne.Initialize(
    2020)
    sw.Initialize(
    0000)
    Dim bounds As Object = gextra.CreateBounds(ne, sw)
    gextra.AddGroundOverlay(bounds, 
    LoadBitmap(File.DirAssets, "up76.png"))
    Note that the bundle in the special folder is not included. You need to download it from the tutorial.

    Updates:

    v2.10 - Adds support for custom info windows (appear when the user clicks on a marker).

    You need to add this event sub and create the custom panel or return Null:
    Code:
    'Return Null for the default marker layout
    Sub gmap_MarkerInfoWindow (OMarker As Object) As Object
       
    Dim SelectedMarker As Marker = OMarker
       
    Dim p As Panel
       p.Initialize(
    "")
       p.Color = 
    Colors.Red
       p.SetLayoutAnimated(
    0100200200)
       
    Dim lbl As Label
       lbl.Initialize(
    "")
       lbl.Text = SelectedMarker.Title
       p.AddView(lbl, 
    1010200200)
       
    Return p
    End Sub
    If you are using a local builder then you need to update to GoogleMaps v1.41: https://www.b4x.com/android/forum/threads/updates-to-internal-libraries.48179/#post-606852
     

    Attached Files:

    Last edited: Aug 15, 2018
    MarcoRome, Mashiane and inakigarm like this.
  2. RichardHirst

    RichardHirst Member Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    You can add the transparency to the image itself.
     
  4. RichardHirst

    RichardHirst Member Licensed User

    Do you mean before you load the image (transparency applied external to the App) or after the image has been loaded...?

    how would I set the transparency with IOS ide..?

    Thanks
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    The image file itself can be semi-transparent.
     
  6. RichardHirst

    RichardHirst Member Licensed User

    Can this be done in code. The external image does not have transparency set..

    Had a look at the Bitmap properties but can not set how to set transparency.

    Thanks
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Currently no.
     
  8. RichardHirst

    RichardHirst Member Licensed User

    Thanks for all you help Erel..
     
  9. Paul Leischow

    Paul Leischow Member Licensed User

    This Class is great for adding circles to a map.
    Was wondering what is the best way to remove circles from the map??
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Modify AddCircle sub and return the circle object.

    Later you can remove this circle by calling:
    Code:
    circle.SetField("map"Null)
     
  11. Paul Leischow

    Paul Leischow Member Licensed User

    Ok, I have the Sub addCircle returning the NativeObject using... Return circle
    Should I be putting this result in a List using Result.add(gextra.addCircle(blah,blah)) ??
    And if so, I'm not understanding how to pull out the info I need so I can use circle.SetField

    Should I maybe not be using the GoogleMapsExtra and making the circle native object global?
    Quite confused ;)
    Thanks.
     
  12. Paul Leischow

    Paul Leischow Member Licensed User

    Well, not sure if this was the right way to do it but it seems to work ;)
    I returned circle as a NativeObject and stored it in a List called Marker.

    Then later, I cycled through the List and put it into a new NativeObject...
    Dim obj As NativeObject=Markers.Get(tmp)
    That allowed me to do
    obj.SetField("map",Null)

    Was this the correct way?
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Yes.
     
  14. vikingivesterled

    vikingivesterled Member Licensed User

    The GoogleMapsExtras library for b4a has a LatLngBoundsBuilder in it which in
    http://www.b4x.com/android/forum/threads/gmaps-zoom.34926/#post-204557
    is used to autozoom a Googlemap according to a set of markers.

    Is there a plan for a similar feature for this b4i class,
    or is there another way of auto zooming (incl. cameraposition) on a set of markers (= lat,long positions)
    for a b4i GoogleMap.
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    New version was uploaded to the first post.

    gextra.ZoomToPoints - Updates the camera position to show all the given points.
    Code:
    Dim l1, l2, l3, l4 As LatLng
    l1.Initialize(
    1010)
    l2.Initialize(
    1020)
    l3.Initialize(
    2020)
    l4.Initialize(
    2010)
    gextra.ZoomToPoints(
    Array(l1, l2, l3, l4))
     
  16. vikingivesterled

    vikingivesterled Member Licensed User

    Excellent addition that, together with a polyline list, works well for displaying a route taken .
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    New version was uploaded with support for polygons.
     
    rboeck likes this.
  18. iCAB

    iCAB Well-Known Member Licensed User

    As I was looking for a solution to control and read back visibility for markers and shapes. I have noticed that the following code doesn't delete the object which in turn can be used to control visibility.

    Code:
    circle.SetField("map"Null)
    So I thought I would share the code I am using, but I wasn't sure if this is the best way to to achieve the results I am looking for

    Here is the code I am using to set the visibility

    Code:
    Public Sub SetMarkerVisiblity( Marker As Marker, blnVisible As Boolean )

        
    Dim m As NativeObject = Marker

        
    If blnVisible = True Then
            m.SetField(
    "map", gm)
        
    Else
            m.SetField(
    "map"Null)
        
    End If

    End Sub
    To check if Visible, I am using the code below, but I was hoping for a cleaner solution

    Code:
    Public Sub IsMarkerVisible( Marker As NativeObject ) As Boolean

        
    Dim blnVisible As Boolean = True
    Try
        
    Dim bTemp As Object = Marker.GetField("map")

    Catch
        blnVisible = 
    False
    End Try
        
    Return blnVisible

    End Sub

    The same can be applied for Polygons and Circles
     
    Last edited: Aug 7, 2016
  19. iCAB

    iCAB Well-Known Member Licensed User

    Hi All,
    I am looking for the code to check if a marker is within the visible region. Basically code equivalent to the B4A code below


    Code:
    Public Sub UpdateProjection1()
       

    #if B4A   
        Projection1 = GoogleMapsExtrasRef.GetProjection( GmapRef )   
        VisibleRegion1 = Projection1.GetVisibleRegion
       
    #else

    #end if                                                                               

    End Sub


    Sub Region_CheckContainsMarker(TLocalMarker As TMarker ) As Boolean
       
        
    Dim blnInRegion As Boolean

    #if B4A
        blnInRegion  = VisibleRegion1.LatLngBounds.Contains(TLocalMarker.Marker.Position)
    #else

    #end if   
       
        
    Return blnInRegion
       
    End Sub
    Thank you
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    Add this code to the OBJC section:
    Code:
    - (BOOL)boundsContain:(GMSCoordinateBounds*) bounds :(B4ILatLng*) ll {
       
    return [bounds containsCoordinate:CLLocationCoordinate2DMake(ll.Latitude, ll.Longitude)];
    }
    - (NSObject*)coordinateBoundsFromProjection:(GMSProjection*) p {
       return [[GMSCoordinateBounds alloc]initWithRegion: [p visibleRegion]];
    }
    Add these subs to GoogleMapsExtra code:
    Code:
    Public Sub GetProjection As NativeObject
       
    Dim ngm As NativeObject = gm
       
    Return ngm.GetField("projection")
    End Sub

    Public Sub GetVisibleBounds As NativeObject
       
    Dim Bounds As NativeObject
       Bounds = no.RunMethod(
    "coordinateBoundsFromProjection:"Array(GetProjection))
       
    Return Bounds
    End Sub

    Public Sub BoundsContain(Bounds As NativeObjectLatLng As LatLngAs Boolean
       
    Return no.RunMethod("boundsContain::"Array(Bounds, LatLng)).AsBoolean
    End Sub
    You can now call it with:
    Code:
    Dim ll As LatLng
    ll.Initialize(
    4230)
    Log(gextra.BoundsContain(gextra.GetVisibleBounds, ll))
     
    iCAB likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice