B4A Library [B4X][XUI] Scale for Google Maps

This custom view class is based on XUI library. It is compatible with B4A, B4i and B4J.
Make sure to always use the latest version of XUI library: https://www.b4x.com/android/forum/t...platform-native-ui-library.84359/#post-534432

It shows the map scale:

SS-2017-12-07_11.32.33.png


It is based on this open source project: https://github.com/pengrad/MapScaleView
The code is written in B4X.

Usage:
- Add MapScale with the designer:
SS-2017-12-07_11.34.25.png


The best way is to put the map itself in a panel and put MapScale above the map and NOT as the the panel's child.

- Handle the CameraChange event and update the scale:
B4X:
Sub gmap_CameraChange (Position As CameraPosition)
   MapScale1.Update(Position.Zoom, Position.Target.Latitude)
End Sub
 

Attachments

  • MapScale.bas
    3.5 KB · Views: 451

Andris

Active Member
Licensed User
Longtime User
I want to change the map scale units programmatically. These are set in Class_Globals by

B4X:
    Private IsMeters As Boolean = True

What's the best way to change IsMeters in code? I tried adding another parameter to Initialize, but this doesn't work, I guess because MapScale1 is initialized in the Designer.
 

DonManfred

Expert
Licensed User
Longtime User
but this doesn't work
B4X:
Public Sub Initialize (Callback As Object, EventName As String, meters As Boolean)
    isMeters = meters ' Did you added this line to the sub too? Additionally to adding the parameter
    mEventName = EventName
    mCallBack = Callback
    #if b4a
    DeviceDensity = Density   
    #else
    DeviceDensity = 1
    #End If
    maxWidth = 90dip
    minWidth = 50dip
    
End Sub
 

Andris

Active Member
Licensed User
Longtime User
Public Sub Initialize (Callback As Object, EventName As String, meters As Boolean)
isMeters = meters
' Did you added this line to the sub too? Additionally to adding the parameter

Yes, I had already added that line to the sub as well as adding the parameter (I named it mUnits because meters is already a variable). But if I then try to Initialize again, it crashes.

I also did this:

Replace in the module, then you can access it from outsides.
Private IsMeters As Boolean = True
by
Public IsMeters As Boolean = True

This doesn't make IsMeters accessible as a MapScale1 property though. Are you saying it should? Would be nice and simple, but don't I need to do some fancy stuff like in [B4X] [XUI] Creating custom views with XUI?
 
Top