B4A Library MapScaleView

This is a wrap for this Github project.

Scale view for Google Maps Android API

image.png


MapScaleView
Author:
DonManfred (wrapper)
Version: 1.01
  • MapScaleView
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • InitializeScaleView (map As GoogleMap)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • update (projection As Projection, cameraPosition As CameraPosition)
    • updateScaleView
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int

Requirement:
You app needs to be ready to use GoogleMaps.

Install:
- Copy content of MapScaleViewVx.yy.zip to your additional libraries folder
- Copy the content of res.MapScaleView.zip toyour project root dir (same folder as files folder)
- Add
B4X:
    #AdditionalRes: ..\res.MapScaleView
to your project.

B4X:
Sub Globals
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
    Private scale As MapScaleView

End Sub

Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("1")
    scale.Initialize("")
end sub

In Mapfragment ready event you setup the ScaleView
B4X:
Sub MapFragment1_Ready
    Log($"map_Ready()"$)
    gmap = MapFragment1.GetMap
    scale.InitializeScaleView(gmap)
end sub

image.png
 

Attachments

  • MapScaleViewV1.01.zip
    9.5 KB · Views: 603
  • res.MapScaleView.zip
    635 bytes · Views: 608

peacemaker

Expert
Licensed User
Longtime User
Strange, but invisible, without any error.
b4a 6.3, emulator v.4.2, real device v.5.0
Firstly made as in the description, next - added the view via the Designer... not visible :(
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
It's a huge project to upload all. Google map is working OK.


B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim GoogleMapsExtras1 As GoogleMapsExtras
    Dim MapSettings As MapUiSettings
    Dim StT As VoiceRecognition
    Dim tim As Timer
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
   Dim gmap As GoogleMap
   Private scale As MapScaleView
   Private Map As MapFragment
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("mymap") ' Google Map and Scale view are here !
scale.Initialize("")
End Sub

Sub Map_Ready
Log("map ready")
gmap = Map.GetMap
If gmap.IsInitialized = False Then
    ToastMessageShow("Map init error", True)
Else
    gmap.MyLocationEnabled = True
    scale.InitializeScaleView(gmap)
    scale.Visible = True
    GoogleMapsExtras1.SetBuildingsEnabled(gmap, True)
End If
End Sub
 
Last edited:

maso1975

Member
Licensed User
Longtime User
Hello DonManfred, is it possible to apply this to OMSDroid with Offline maps?
 

Andris

Active Member
Licensed User
Longtime User
Thank you Don for this helpful view. Works great in my app.

One question though. I haven't been successful in changing the text size or color and wonder if that can be done. In your third example screenshot, you definitely show a bigger font size and a color other than black. However, Properties doesn't include TextSize or TextColor, and assigning values in Designer has no effect either. Is there something I'm missing?

If in fact these Properties aren't supported, can they be added?
 

gravel

Member
Licensed User
Longtime User
Hello DonManfred, would you consider updating the lib to the current 1.2.1 version which, along with other changes, supports a scale bar in Miles/Feet as well as Kilometres/Metres?
 

DonManfred

Expert
Licensed User
Longtime User
supports a scale bar in Miles/Feet as well as Kilometres/Metres?

B4X:
Sub MapFragment1_Ready
    Log("MapReady()")
    gmap = MapFragment1.GetMap
    scale.IsMiles = True
 

Attachments

  • MapsScaleViewV2.0.zip
    9.6 KB · Views: 462

gravel

Member
Licensed User
Longtime User
Wow, thanks DonManfred. But I can't get it to show. There's no longer a
scale.InitializeScaleView(gmap) ... is that not needed any longer?

What I've got is:
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #AdditionalRes: ..\res.MapScaleView   
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
    #AdditionalJar: com.google.android.gms:play-services-maps   
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
    Private MapScaleView1 As MapScaleView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    MapScaleView1.Initialize("")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub MapFragment1_Ready
    gmap = MapFragment1.GetMap
    MapScaleView1.IsMiles = True
    MapScaleView1.BringToFront
End Sub
 

IdasI4A

Active Member
Licensed User
Longtime User
Great. +10
One suggestion, update could you return the value of the scale?
That is:
B4X:
Dim M as int
M=MapScaleView1.update(Position.Zoom,Position.Target.Latitude)
log("Metros=" & M)
 
Top