Android Question GoogleMapsExtras ?

Discussion in 'Android Questions' started by johnerikson, Mar 12, 2015.

  1. johnerikson

    johnerikson Active Member Licensed User

    Following code below crash using GoogleMapExtras!
    This happens suddenly after had using the app during half a year!
    I now compile with B4A 4.30
    Use:Windows 7 Ultimat
    lib: Core 4.01, GoogleMaps 1.02, GoogleMapExtras 1.80
    GoogleMapsExtras.jar date 2014-10-20

    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: B4A GisMap
        
    #VersionCode: 1
        
    #VersionName:
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: unspecified
        
    #CanInstallToExternalStorage: False
        
    #AdditionalRes: L:\Program\Android\adt-bundle-windows-x86_64-20140702\sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

    #End Region

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

    Sub Process_Globals
        
    Dim GoogleMapsExtras1 As GoogleMapsExtras
    End Sub

    Sub Globals
       
    Dim mFragment As MapFragment
       
    Dim gmap As GoogleMap
       
    Dim MapPanel As Panel
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
       MapPanel.Initialize(
    "")
       
    Activity.AddView(MapPanel, 00100%x100%y)
       
    If mFragment.IsGooglePlayServicesAvailable = False Then
          
    ToastMessageShow("Google Play services not available."True)
       
    Else
          mFragment.Initialize(
    "Map", MapPanel)
       
    End If
    End Sub
    Sub Map_Ready
       
    Log("map ready")
       gmap = mFragment.GetMap
       
    If gmap.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map."True)
       
    Else  
            
    Dim MarkerOptions1 As MarkerOptions
            MarkerOptions1.Initialize
    '       
            'full function
            Dim tmpMarker As Marker
            tmpMarker= gmap.AddMarker3(
    64.4761918.3980,"Sparpkt",LoadBitmap(File.DirAssets, "ring.png")) ' Ok so far

            
    'but Crasch using GoogleMapsExtras below
            Dim BD As BitmapDescriptor
            
    Dim BF As BitmapDescriptorFactory
            BD=BF.FromAsset(
    "ring.png")
                   
            MarkerOptions1.Icon(BD)       
            MarkerOptions1.Position2(
    64.7961918.3980)
            tmpMarker=GoogleMapsExtras1.AddMarker(gmap, MarkerOptions1.Snippet(
    "pkt").Title("1"))
    'this line crash see error message, quote below
      
            
    Dim cp As CameraPosition
            cp.Initialize(
    6418, gmap.CameraPosition.Zoom)
            gmap.AnimateCamera(cp)
       
    End If
    End Sub
    The problem with 'gmap.addmarker' mode are the presentation of the bitmap. In the moment I got a 1/4 (up to the left)of the hole .png file as a marker on map.

    What had happen with GoogleMapExtras?
    Is it possible to create symbols as markers more then using LoadBitmap(File...?
     
    Last edited: Mar 12, 2015
  2. eurojam

    eurojam Well-Known Member Licensed User

    ....what code??
     
  3. johnerikson

    johnerikson Active Member Licensed User

    Sorry, some mistake happened!
    Now I have completed the question!
     
  4. eurojam

    eurojam Well-Known Member Licensed User

    John,
    if you use a drawable instead of your ring.png from the asset folder (from the res folder) it will work:

    Code:
    ...
    Dim AndroidResources1 As AndroidResources   
    Dim MyDrawable1 As BitmapDrawable
    Dim Icon1 As Bitmap
    MyDrawable1=AndroidResources1.GetApplicationDrawable(
    "ring")
    Icon1=MyDrawable1.Bitmap
    Dim BitmapDescriptor1 As BitmapDescriptor
    Dim BitmapDescriptorFactory1 As BitmapDescriptorFactory
    BitmapDescriptor1=BitmapDescriptorFactory1.FromBitmap(Icon1) 
    MarkerOptions1.Icon(BitmapDescriptor1)   
    MarkerOptions1.Position2(
    64.7961918.3980).Snippet("pkt").Title("1")
    tmpMarker=GoogleMapsExtras1.AddMarker(gmap, MarkerOptions1)
    ...
     
  5. johnerikson

    johnerikson Active Member Licensed User

    Thanks for the quick feedback!
    It gave me a clue to the solution!

    I don't understand what "ring" in MyDrawable1 = AndroidResources1; GetApplicationDrawable ("ring") really is!
    Therefore, the program crashes on line Icon1=MyDrawable1.Bitmap.
    But, I solved it like this ...
    I did a class that creates bitmapdrawable, which means I don't need to use AndroidResources.
    But you must be careful to create circle and rect with the correct dimensions, otherwise it will move around the map when you zooms

    It would still be good to know about what that "ring" in MyDrawable1 = AndroidResources1; GetApplicationDrawable ("ring") really is?

    Code:
    'Class module Create BitmapDrawable 
    Private Sub Class_Globals
        
    Dim bdRing As BitmapDrawable   
    End Sub

    'Initializes the object, returns a BitmapDrawable.
    Public Sub Initialize() As BitmapDrawable

        
    Dim r As Rect
        
    Dim bmp As Bitmap
        
    Dim cnvs As Canvas

        bmp.InitializeMutable(
    20,20)
        cnvs.Initialize2(bmp)

        r.Initialize(
    0,0,20,20)
        cnvs.DrawRect(r, 
    Colors.Transparent, False,2)
        cnvs.DrawCircle(
    10,10,  10 ,Colors.Red ,False3)
        bdRing.Initialize( bmp)
        
    Return bdRing
    End Sub
    I change your code like this
    Code:
    Dim MarkerOptions1 As MarkerOptions
            MarkerOptions1.Initialize
            
    Dim tmpMarker As Marker
            
    Dim ring As CirclDrawAble ' class as create drawables
            'Dim AndroidResources1 As AndroidResources  
            Dim MyDrawable1 As BitmapDrawable
            
    Dim Icon1 As Bitmap
           
            
    'MyDrawable1=AndroidResources1.GetApplicationDrawable ( "ring")
            MyDrawable1 = ring.Initialize

            Icon1=MyDrawable1.Bitmap
            
    Dim BitmapDescriptor1 As BitmapDescriptor
            
    Dim BitmapDescriptorFactory1 As BitmapDescriptorFactory
            BitmapDescriptor1=BitmapDescriptorFactory1.FromBitmap(Icon1)
            MarkerOptions1.Icon(BitmapDescriptor1)  
            MarkerOptions1.Position2(
    64.58998018.683856).Snippet("pkt").Title("1")
            tmpMarker=GoogleMapsExtras1.AddMarker(gmap, MarkerOptions1)
     
  6. eurojam

    eurojam Well-Known Member Licensed User

    John,
    you made your bitmapdescriptor like this:
    Code:
    BD=BF.FromAsset("ring.png")
    If you copy the ring.png to the objects/res/drawable folder and put it to readonly then you can load it like
    Code:
    MyDrawable1=AndroidResources1.GetApplicationDrawable("ring")
    without the fileextension. But it represents the ring.png
     
  7. johnerikson

    johnerikson Active Member Licensed User

    Yep! It works.
    Now I have two or more alternative solutions to the problem, as well as further knowledge.
    I noticed that the ring.png must be read-only on res\drawable else .png-file was deleted!
    Thank you very much!
     
  8. DonManfred

    DonManfred Expert Licensed User

    There is a solution about this. Search for documentation about #AdditionalRes command.
    You can also have a deeper look at the AdditionalRes command in this example.
    If you do it like this way all files in the resources-folder dont need to have readonly flag set. The files here are dont deleted while compiling too.
     
  9. ronnhdf

    ronnhdf Member Licensed User

    Can you please provide a complete demo time at disposal
     
  10. DonManfred

    DonManfred Expert Licensed User

    See this Example. It is using the Additionalres Command and a additional folder i told about
     
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