Android Question GoogleMapsExtra can't load marker image?

Discussion in 'Android Questions' started by Roger Daley, Aug 14, 2019.

  1. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Hi All again,


    An existing working Google Maps App being updated to match new requirements.

    In creating the markers an error is shown indicating the image for the marker can't be decoded. The image "markerghost.png" is the same as it has always been.
    The error indicates .bmp files, I have tried several .bmp files but the same error is produced.

    The Sub producing the error is below:

    Code:
    Sub mFragment_Ready

      gmap = mFragment.GetMap
     
        
    '  Sleep(100)         same result as  "rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)"

    '   'Added as part of upgrade 10 Aug 19                            Does not work.
    '   Log("Point1")
    '    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    '    Log("Point2")                                                                                                        'This point is logged
    '    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)       'Bypasses the rest of the Sub
    '    Log("Point3")                                                                                                        'This point is not logged
    '    gmap.MyLocationEnabled = Result
    '    Log("result = "&Result)
     
     
    '******* The following code in the Sub has not changed from the original working App  ********
       If gmap.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map."True)
            
    Log("BTSMarkerError")
       
    Else
            
    'Create BTSMarker Options including ICON
            Private BTSOptions As MarkerOptions
            
    Private BitmapDescriptor1 As BitmapDescriptor
              
    Private BitmapDescriptorFactory1 As BitmapDescriptorFactory           
            
            BTSOptions.Initialize
            BTSOptions.Draggable(
    True
            BTSOptions.Position2(BTSLat, BTSLng).Snippet(
    "").Title("")
            BTSOptions.Anchor(
    0.50.5)         
            BitmapDescriptor1=BitmapDescriptorFactory1.FromAsset(
    "markerghost.png")        'Tried several  .bmp files,  the error below remained.
            'BitmapDescriptor3=BitmapDescriptorFactory3.FromAsset("markerghost.bmp")       
            BTSOptions.Icon(BitmapDescriptor1)       
            
    'Create BTSmarker
            BTSMarker=GoogleMapsExtras1.AddMarker(gmap, BTSOptions)        'Error  com.google.maps.api.android.lib6.common.apiexception.a: Failed to decode image. The provided image must be a Bitmap.
            
            
            
    'Create LANDMarker Options including ICON
            Private LANDOptions As MarkerOptions
            
    Private BitmapDescriptor2 As BitmapDescriptor
              
    Private BitmapDescriptorFactory2 As BitmapDescriptorFactory
            
            LANDOptions.Initialize
            LANDOptions.Draggable(
    True
            LANDOptions.Position2(LANDLat, LANDLng).Snippet(
    "").Title("")
            LANDOptions.Anchor(
    0.50.5)
            BitmapDescriptor2=BitmapDescriptorFactory2.FromAsset(
    "markerghost.png")
            LANDOptions.Icon(BitmapDescriptor2)
            
    'Create LANDMarker marker
            LANDMarker = GoogleMapsExtras1.AddMarker(gmap, LANDOptions)
            
            
    'Create BEndMarker Options including ICON
            Private BEndOptions As MarkerOptions
            
    Private BitmapDescriptor3 As BitmapDescriptor
              
    Private BitmapDescriptorFactory3 As BitmapDescriptorFactory
            
            BEndOptions.Initialize
            BEndOptions.Draggable(
    True
            BEndOptions.Position2(BLat, BLng).Snippet(
    "").Title("")
            BEndOptions.Anchor(
    0.50.5)
            BitmapDescriptor3=BitmapDescriptorFactory3.FromAsset(
    "markerghost.png")
            
            BEndOptions.Icon(BitmapDescriptor3)
            
    'Create BEndMarker marker
            BEndMarker = GoogleMapsExtras1.AddMarker(gmap, LANDOptions)       
            
            
    Private AnyDragListener As OnMarkerDragListener
            AnyDragListener.Initialize(
    "AnyDragListener")
            GoogleMapsExtras1.SetOnMarkerDragListener(gmap,AnyDragListener)

            PathDistance   
            ABearingCalc
            OffSet
            
            
    Select Mode
                
    Case 0
                    pnlABDispLatLng.SendToBack           
                    BTSIV.BringToFront
                    LMIV.BringToFront
                    AEndIV.SendToBack
                    BEndIV.SendToBack   
                    pnlDispLatLng.BringToFront
                    
                    
    'Locate Markers
                    Private LL As LatLng
                        LL.Initialize(BTSLat, BTSLng) 
    'the new Position
                        BTSMarker.Position = LL
                    
    Private LL As LatLng
                        LL.Initialize(LANDLat, LANDLng) 
    'the new Position
                        LANDMarker.Position = LL
            
                    
    'Center Map.  Zoom in/out to display IV's
                    cp.Initialize2(MapLat, MapLng, 1800 )
                    gmap.MoveCamera(cp)
                    cp.Initialize2(MapLat, MapLng, MapZoom, 
    00 )
                    gmap.MoveCamera(cp)                   

                    
    'Draw Lines
                    HorizonPointLatLng
                    DrawLandMarkLine
                    DrawAntBearingLine

                
    Case 1   
                    pnlDispLatLng.SendToBack
                    BTSIV.SendToBack
                    LMIV.BringToFront
                    AEndIV.BringToFront
                    BEndIV.BringToFront
                    pnlABDispLatLng.BringToFront

                    
    Private LL As LatLng
                        LL.Initialize(ALat, ALng) 
    'the new Position
                        BTSMarker.Position = LL
                    
    Private LL As LatLng
                        LL.Initialize(BLat, BLng) 
    'the new Position
                        BEndMarker.Position = LL
                    
    Private LL As LatLng
                        LL.Initialize(ABLandLat, ABLandLng) 
    'the new Position
                        LANDMarker.Position = LL
                    
                    cp.Initialize2(ABMapLat, ABMapLng, 
    1800 )
                    gmap.MoveCamera(cp)
                    cp.Initialize2(ABMapLat, ABMapLng, ABMapZoom, 
    00 )
                    gmap.MoveCamera(cp)
                    DrawLandMarkLine
                    DrawAntBearingLine           
            
    End Select       

            
    Select Mode
                
    Case 0           
                    HorizonPointLatLng
                    DrawLandMarkLine
                    DrawAntBearingLine               
                    cp.Initialize2(MapLat, MapLng, MapZoom, MapBearing, 
    0 )
                    gmap.MoveCamera(cp)
                    gmap.maptype = MapTypeInt      
    'MapTypeInt: 1=Road Map, 2=Satellite, 3=Terrain, 4=Satellite with Labels
                    gmap.MyLocationEnabled = True
                    gmap.GetUiSettings.MyLocationButtonEnabled = 
    False
                    gmap.GetUiSettings.CompassEnabled = 
    True   
                
    Case 13
                    DrawLandMarkLine
                    DrawAntBearingLine                               
                    cp.Initialize2(ABMapLat, ABMapLng, ABMapZoom, ABMapBearing, 
    0 )
                    gmap.MoveCamera(cp)
                    gmap.maptype = ABMapTypeInt      
    'ABMapTypeInt: 1=Road Map, 2=Satellite, 3=Terrain, 4=Satellite with Labels
                    gmap.MyLocationEnabled = True
                    gmap.GetUiSettings.MyLocationButtonEnabled = 
    False
                    gmap.GetUiSettings.CompassEnabled = 
    True   
            
    End Select   
       
    End If
       Timer2.Initialize(
    "Timer2",2500)                     'Gives GPS time to lock before activating SunDial calcs. [2500ms]
       Timer2.Enabled = True
      
    End Sub



    The part log file is below:

    The ZIP is uploaded, note the Key is a dummy and would need to be replaced with a valid Map Key.

    Any help greatly appreciated. It's probably obvious but I can't see why the changes in setting up the map would cause issues with this code.

    Regards Roger
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    Why aren't you using gmap.AddMarker3 ?
     
  3. Roger Daley

    Roger Daley Well-Known Member Licensed User

    :(Erel,
    I wrote this 4-5 yrs ago, I vaguely remember there was an issue with what I was trying to do. The issue was solved at the time by using the GoogleMapExtras code. I have no idea why I didn't use gmap.AddMarker3 but I can remember there was a reason.

    CURRENT SITUATION: I have changed the code to create the three markers using gmap.AddMarker3 and the code compiles without error but the map does not load properly. The one icon I can touch on screen does not respond.

    1. I can't check if there is a problem with the icons created this way.
    2. I still need to find out why the existing code has ceased to work. [It would be great if I can use Addmarker3 but I think I will still have the problem.]
    3. I will have to find out why the map dos not load correctly before looking at icons. I have no idea what it may be but I'll start searching the forum/Google. I will probably come back with a new question/new thread.:(

    Regards Roger
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    The error is related to the virtual assets folder in debug mode. The simplest solution is to load the bitmap and then set it with FromBitmap instead of FromAssets:
    Code:
    Dim MarkerGhost As Bitmap = LoadBitmap(File.DirAssets, "markerghost.png")
    BitmapDescriptor1=BitmapDescriptorFactory1.FromBitmap(MarkerGhost)
    'and several other places as well
    You will get a different error after this because you cannot enable MyLocationEnabled until you request and receive the FINE location permission.
     
  5. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Thanks Erel,

    That certainly fixed that problem and you are correct I now have the next issue.
    If I include the request code as in the tutorial I get one error, if I enable MyLocation in the Designer and exclude the request code I get a different error.

    I will make myself a coffee and start searching for the answer. :confused:

    Once again many thanks.
    Regards Roger
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You should start a new thread for this if you weren't able to solve it. MyLocation should be disabled in the designer (it is mentioned in the tutorial)
     
    Roger Daley likes this.
  7. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Yes Erel, it was a thankyou, not a question, sorry to confuse you.
    Roger
     
    Erel likes this.
  8. Erel

    Erel Administrator Staff Member Licensed User

    I didn't mean to scold (?). It was a practical answer. Everything is good :)
     
    Roger Daley likes this.
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