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

Discussion in 'Android Questions' started by Waldemar Lima, Feb 6, 2018.

  1. Waldemar Lima

    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 .
     
  2. DonManfred

    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...
     
  3. Waldemar Lima

    Waldemar Lima Active Member Licensed User

    sorry about that xD

    here is the code what i am trying >

    Code:
    #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(1040"test")
        m1.Snippet = 
    "This is the snippet"
        
    End Sub

    Sub gmap_MarkerClick (SelectedMarker As MarkerAs Boolean
        
    Log(SelectedMarker.Snippet)
        
    Return True
    End Sub
     
  4. DonManfred

    DonManfred Expert Licensed User

    I dont see anything where you are changing something!?

    What does not work?
     
  5. Waldemar Lima

    Waldemar Lima Active Member Licensed User

    Sorry , i had send a wrong code , the right code is =

    Code:
    #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"32dip32dipTrue)
        
    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(1040"test",bmp) 'When i add bmp icon dont appear marker
        m1.Snippet = "This is the snippet"
        
    End Sub

    Sub gmap_MarkerClick (SelectedMarker As MarkerAs Boolean
        
    Log(SelectedMarker.Snippet)
        
    Return True
    End Sub
    Icon dont appear .
     
  6. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    It is very easy.

    put your icon in to this path in your project:
    Code:
    \Objects\res\drawable-nodpi
    in this example is my icon called "marker1.png" but the ".png" we dont need in the code.

    Code:
    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)
     
  7. Waldemar Lima

    Waldemar Lima Active Member Licensed User

  8. Erel

    Erel Administrator Staff Member Licensed User

    You don't need to use a resource here. The code in the first post should work.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice