B4i Library [class]GoogleMapsExtra

Status
Not open for further replies.
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:
B4X:
gextra.Initialize(gmap)
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.png"))

Note that the bundle in the special folder is not included. You need to download it from the tutorial.

Updates:

v2.15 - New AnimateCameraWithDuration method. Same as gmap.AnimateCamera with configurable duration.
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:
B4X:
'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(0, 1, 0, 0, 200, 200)
   Dim lbl As Label
   lbl.Initialize("")
   lbl.Text = SelectedMarker.Title
   p.AddView(lbl, 10, 10, 200, 200)
   Return p
End Sub
 

Attachments

  • GoogleMapsExtra.zip
    10.7 KB · Views: 81
Last edited:

RichardHirst

Member
Licensed User
Longtime 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
 

RichardHirst

Member
Licensed User
Longtime 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
 

Paul Leischow

Member
Licensed User
Longtime User
This Class is great for adding circles to a map.
Was wondering what is the best way to remove circles from the map??
 

Paul Leischow

Member
Licensed User
Longtime 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.
 

Paul Leischow

Member
Licensed User
Longtime 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?
 

iCAB

Well-Known Member
Licensed User
Longtime 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.

B4X:
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

B4X:
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

B4X:
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:

iCAB

Well-Known Member
Licensed User
Longtime 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


B4X:
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
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Add this code to the OBJC section:
B4X:
- (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:
B4X:
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 NativeObject, LatLng As LatLng) As Boolean
   Return no.RunMethod("boundsContain::", Array(Bounds, LatLng)).AsBoolean
End Sub

You can now call it with:
B4X:
Dim ll As LatLng
ll.Initialize(42, 30)
Log(gextra.BoundsContain(gextra.GetVisibleBounds, ll))
 
Status
Not open for further replies.
Top