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

Discussion in 'Additional libraries, classes and official updates' started by Erel, Dec 7, 2017.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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:

    [​IMG]

    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:
    [​IMG]

    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:
    Code:
    Sub gmap_CameraChange (Position As CameraPosition)
       MapScale1.Update(Position.Zoom, Position.Target.Latitude)
    End Sub
     

    Attached Files:

  2. Andris

    Andris Active Member Licensed User

  3. Andris

    Andris Active Member Licensed User

    I want to change the map scale units programmatically. These are set in Class_Globals by

    Code:
    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.
     
  4. DonManfred

    DonManfred Expert Licensed User

    Code:
    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
     
  5. klaus

    klaus Expert Licensed User

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

    Andris Active Member Licensed User

    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:

    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?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    You cannot modify the Initialize method as this is a custom view.

    Change IsMeters to public and press enter. Otherwise it will not appear immediately.
     
  8. Andris

    Andris Active Member Licensed User

    :D Thanks Erel - you were right, I hadn't pressed Enter. I should have known better;)
     
Loading...