Android Question how can i do to change GoogleMaps Marker Icon ?

Waldemar Lima

Active Member
Licensed User
hi everyone !

i would like know how can i change marker icon using Erel Library From GoogleMaps v2 tutorial .
 

DonManfred

Expert
Licensed User
Hiding the code you have tried so far does not help us to help you
Remember the marker to change it later...
 
Upvote 0

Waldemar Lima

Active Member
Licensed User
sorry about that xD

here is the code what i am trying >

B4X:
#Region  Project Attributes
   #ApplicationLabel: Nereu Bus Tracker
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
    #AdditionalJar: com.google.android.gms:play-services-maps

#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: False
#End Region

'Activity module
Sub Process_Globals

End Sub

Sub Globals
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
    Private Button1 As Button
    Private Button1_n As Button
End Sub

Sub Button1_n_click
    Activity.LoadLayout("1")
    
End Sub

Sub Button1_Click
            
    Activity.LoadLayout("2")
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Please install Google Play Services.", True)
    End If
    Dim width = Activity.Width
    Dim height = Activity.Height
    
    Log("width = "&width)
    Log("height = "&height)
End Sub

Sub MapFragment1_Ready
    
    gmap = MapFragment1.GetMap
    gmap.MyLocationEnabled = True
    Dim m1 As Marker = gmap.AddMarker(10, 40, "test")
    m1.Snippet = "This is the snippet"
    
End Sub

Sub gmap_MarkerClick (SelectedMarker As Marker) As Boolean
    Log(SelectedMarker.Snippet)
    Return True
End Sub
 
Upvote 0

Waldemar Lima

Active Member
Licensed User
Sorry , i had send a wrong code , the right code is =

B4X:
#Region  Project Attributes
   #ApplicationLabel: Nereu Bus Tracker
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
    #AdditionalJar: com.google.android.gms:play-services-maps

#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: False
#End Region

'Activity module
Sub Process_Globals

End Sub

Sub Globals
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
    Private Button1 As Button
    Private Button1_n As Button
    Private bmp As Bitmap
End Sub

Sub Button1_n_click
    Activity.LoadLayout("1")
    
End Sub

Sub Button1_Click
            
    Activity.LoadLayout("2")
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    bmp = LoadBitmapResize(File.DirAssets, "bus_icon_redlow.png", 32dip, 32dip, True)
    Log(File.DirAssets)
    Activity.LoadLayout("1")
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Please install Google Play Services.", True)
    End If
    Dim width = Activity.Width
    Dim height = Activity.Height
    
    Log("width = "&width)
    Log("height = "&height)
End Sub

Sub MapFragment1_Ready
    
    gmap = MapFragment1.GetMap
    gmap.MyLocationEnabled = True
    Dim m1 As Marker = gmap.AddMarker3(10, 40, "test",bmp) 'When i add bmp icon dont appear marker
    m1.Snippet = "This is the snippet"
    
End Sub

Sub gmap_MarkerClick (SelectedMarker As Marker) As Boolean
    Log(SelectedMarker.Snippet)
    Return True
End Sub

Icon dont appear .
 
Upvote 0

Alexander Stolte

Expert
Licensed User
It is very easy.

put your icon in to this path in your project:
B4X:
\Objects\res\drawable-nodpi

in this example is my icon called "marker1.png" but the ".png" we dont need in the code.

B4X:
Dim Icon As BitmapDrawable
Dim AndroidResources1 As AndroidResources
Dim gmap As GoogleMap

Icon = AndroidResources1.GetApplicationDrawable("marker1")
gmap.AddMarker3(lat,lon,"My custom Marker",Icon.Bitmap)
 
Upvote 0
Top