iOS Question Google Maps - Alternative Markers

RichardN

Active Member
Licensed User
The standard 'teardrop' marker available in Google Maps that shows the snippet when tapped is pretty easy to use, but I am looking for something permanently visible.... Like a little rectangle maybe 3%x by 3%y slightly offset from the waypoint. Ideally something like a 'speech bubble' that can display a couple of line of major/minor text.

Any suggested methods?
 

RichardN

Active Member
Licensed User
Thanks Erel.

AddGroundOverlay is fine for adding a bitmap within defined bounds. However that limits the programmer to a selection of bitmap assets which do not afford any flexibility. An object with text properties would be much better.

The standard Google waypoint marker can already be customised. The standard Google snippet box could actually serve the purpose perfectly... if only it could be made to remain in view by default - not just when it is clicked.
 
Upvote 0

rboeck

Well-Known Member
Licensed User
I was able to create marker bitmaps at runtime for android and b4j; but i was not successfull to make it for b4i. Maybe you could explain or make a video how bitmap, canvas work together especially how to combine, load, save and use as marker.
 
Upvote 0

RichardN

Active Member
Licensed User
Erel, I think there is a fundamental problem with using your suggestion of employing AddGroundOverlay.

The whole point of using the Google Maps API is that the map and programmer added features will scale & zoom as the user navigates around the interface. Surely, if you add a bitmap using gmap.AddGroundOverlay then the bounds of the bitmap remain fixed which make it unsuitable in a scaleable environment?
 
Upvote 0

RichardN

Active Member
Licensed User
It is strange that neither the Android nor the iOS Google maps API support such simple functionality.

You can of course replace the marker bitmap with an offset custom one (with text) created in a Canvas at run-time? I will have a play with that.
 
Upvote 0

RichardN

Active Member
Licensed User
This arrangement seems to work OK.

I have added a Sub that produces a bitmap text label at runtime then added the 'SetGroundAnchor' method to the GoogleMapsExtra class in order to offset both the bespoke waypoint marker and the text bitmap. The vertical text alignment in the bitmap needed a bit of fiddling but the result is satisfactory.

Both elements are added as markers with the maps API so retaining all the pan/scan/zoom functionality within Google Maps.

B4X:
Sub Process_Globals
 
    Private Page3 As Page
    Private Gmap As GoogleMap
    Private GMX As GoogleMapsExtra
 
    Type TextMetric(Height As Float,Width As Float)
    Private TM As TextMetric
 
End Sub


Sub DrawMap
   
     ..................
     ..................
     Dim wp As Bitmap                                                                  'Use a custom waypoint bitmap
     wp.Initialize(File.DirAssets,"waypoint.png")
 
      Dim m1 As Marker = Gmap.AddMarker3(Latitude,Longitude,"", wp)       'Add custom waypoint markers
      GMX.SetGroundAnchor(m1,0.5,0.5)
       
      Dim m2 As Marker = Gmap.AddMarker3(Latitude,Longitude,"", TextLabel(Ident,Font.DEFAULT))
      GMX.SetGroundAnchor(m2,0.5,1.5)
       ..................
       ..................

End Sub


Sub TextLabel(Text As String, Font1 As Font) As Bitmap
 
    TM.Height = Text.MeasureHeight(Font1)
    TM.Width = Text.MeasureWidth(Font1)

    Dim c As Canvas
    c.Initialize(Gmap)
    Dim r As Rect
    r.Initialize(0,0,TM.Width + 10dip,TM.Height + 5dip)
    c.DrawRectRounded(r,Colors.White,True,1,6)
    c.DrawText(Text,r.Width /2 ,r.Height /2 + 8dip, Font1,Colors.Black,"CENTER")
 
    Dim bm As Bitmap = c.CreateBitmap
    Return bm.Crop(0,0,r.Width,r.Height)
 
End Sub

googlemap.png
 
Last edited:
Upvote 0
Top