Android Question Google Map Marker icon Chopped

Discussion in 'Android Questions' started by iCAB, May 11, 2016.

  1. iCAB

    iCAB Well-Known Member Licensed User

    Hi All

    While trying to scale the Marker icon to look bigger on a tablet, I ran into an issue where the Marker icon look chopped ( only a small part of it shows ).

    The code below shows the working code followed by the code that will cause the issue.

    Dim BitmapDescriptor1 As BitmapDescriptor
    Dim BitmapDescriptorFactory1 As BitmapDescriptorFactory

    'This code works ok  
    'This code shows chopped icons
        'Dim bBitMap As Bitmap = LoadBitmap(File.DirAssets, TLocalMarker.TMarkerSettings.IconFile)
    Can someone clarify please

    Thanks in advance
  2. eurojam

    eurojam Well-Known Member Licensed User

    Put your icons (icon1.png) into the resource folder, e.g. ..\Objects\res\drawable, make them read only and then load it as an AndroidResource like this:
    Dim Markeropts As MarkerOptions
    Dim AndroidResources1 As AndroidResources
    Dim BitmapDescriptor1 As BitmapDescriptor
    Dim BitmapDescriptorFactory1 As BitmapDescriptorFactory
    Dim Icon As Bitmap
    Dim Mydrawable1 As BitmapDrawable
    Dim Marker1 As Marker=GoogleMapsExtras1.AddMarker(GoogleMap1, Markeropts)
  3. iCAB

    iCAB Well-Known Member Licensed User

    Thanks eurojam for the reply.

    But my icons are downloadable from the host, what would be the workaround?
  4. Erel

    Erel Administrator Staff Member Licensed User

    What is the image size? Have you tried to resize it (search for CreateScaledBitmap)?
    Last edited: May 15, 2016
  5. iCAB

    iCAB Well-Known Member Licensed User

    Ok let me clarify.
    I started by using CreateScaledBitmap. That's when I encountered the issue in the first place.
    To debug the issue, I started removing code line by line, then I noticed that simply by using the code commented out in my original post the problem appears.

    The image I am using is 60x60 (3.34K)
  6. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried it with a smaller image?
  7. iCAB

    iCAB Well-Known Member Licensed User

    I just tried a 24x24 image.
    I got the same results
  8. Erel

    Erel Administrator Staff Member Licensed User

    Try it with this code:
    Sub MapFragment1_Ready
       gmap = MapFragment1.GetMap
    Dim m1 As Marker = gmap.AddMarker3(1030"test", SetBitmapDensity(LoadBitmap(File.DirAssets, "smiley.png")))
       m1.Snippet = 
    "This is the snippet"
    End Sub

    Sub SetBitmapDensity(b As BitmapAs Bitmap
    Dim jo As JavaObject = b
    Dim den As Int = Density * 160
    Return b
    End Sub
    jose luis gudino likes this.
  9. iCAB

    iCAB Well-Known Member Licensed User

    Thanks Erel for your continuous support.

    Here is what I found out while trying the above code.

    1. if I use the original image 60x60 (or 60x30) and I use the above code as is, I have the exact same results as in my original code ( the image looks too small on my tablet)

    2. If I change the multiplier from "160" to "80", the images are chopped in exactly the same way the non working code in my original post did ( basically scaling the image up in size by changing the density is not working )

    3. if I use a higher resolution image, say 240x120 and change the multiplier up, for example ( 320 or 640 ), the image will be scaled down in size properly, which will allow to the achieve the desired results.

    My only question is: Would I run into more issues by using the larger images for display many icons on the map

    Thanks again
  10. Erel

    Erel Administrator Staff Member Licensed User

    Make sure to reuse the same bitmap objects (load each image file) once. The number of markers shouldn't matter.
    iCAB likes this.
  11. iCAB

    iCAB Well-Known Member Licensed User

    Hi Erel

    The above approach seems to be working good for resizing the icons whoever the icon location on the map seems to be off.

    Here is a bit more details:
    1. If I use a 60x30 icon without resizing the icon and if I use the code below, then icon location is exactly where it is supposed to be

    Dim  mx As MarkerExtras
    If TLocalMarker.TMarkerSettings.blnAnchorToMidPoint = True Then
    End If

    2. if I use a larger icon together with SetBitmapDensity as described earlier in this thread, it seems as if the icon displayed with a bit of an offset from the exact location (most likely due to the anchor point )

    Any advice is greatly appreciated

    Thanks in advance
  12. Erel

    Erel Administrator Staff Member Licensed User

    What happens when you add a marker without changing the anchor?
  13. iCAB

    iCAB Well-Known Member Licensed User

    Hi Erel
    Same results
  14. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload an example?
  15. iCAB

    iCAB Well-Known Member Licensed User

    Sorry for the delay. Here is a sample code that shows the issue

    Sub MapFragment1_Ready
        GoogleMap1 = MapFragment1.GetMap
    If GoogleMap1.IsInitialized = False Then
    ToastMessageShow("Error initializing map."True)
    '60x30 icon
            Dim Marker2 As Marker = GoogleMap1.AddMarker3(52.756190.3980"test1",  SetBitmapDensity2(LoadBitmap(File.DirAssets, "image1.png"),160))
    '240 x 120
            Dim Marker3 As Marker = GoogleMap1.AddMarker3(52.756190.3980"test2",  SetBitmapDensity2(LoadBitmap(File.DirAssets, "Image2.png"),640))
    Dim CameraPosition1 As CameraPosition

    End If
    End Sub

    Sub SetBitmapDensity2(b As Bitmap, Multiplier As Int) As Bitmap
    Dim jo As JavaObject = b
    Dim den As Int = Density * Multiplier
    Return b
    End Sub
    Last edited: Jul 12, 2016
  16. Erel

    Erel Administrator Staff Member Licensed User

    Please upload it as a project (File - Export as zip).
  17. iCAB

    iCAB Well-Known Member Licensed User

    I am attaching a zip file as requested.
    Please note that I changed the package name and removed the Map Key from the manifest file.
    If you like I can email you the project including the key

    Attached Files:

  18. Erel

    Erel Administrator Staff Member Licensed User

    Why are you setting the multiplier to 640 if you want to show a large icon? It should be 160:

  19. iCAB

    iCAB Well-Known Member Licensed User

    Let me clarify.

    If I use the small image 60x30 on a high resolution tablet the image looks very small (hard to see )
    What I wanted to achieve is the following:
    Declare an array of multipliers with values such as (160,320,640)
    Use the larger image, as the base image, and auto select a value from the array based on the screen resolution.
    So for a tablet with high resolution and bigger screen, I can use 320
    And for a phone with low resolution and smaller screen , I can use 640

    However the issue, is the location of the icons, which becomes even more obvious when using 640 as multiplier and even worse if you rotate the marker.

    if you add this block of code after adding Marker3, you will see what I am saying:

    Dim Marker4 As Marker = GoogleMap1.AddMarker3(52.756190.3980"test4",  SetBitmapDensity2(LoadBitmap(File.DirAssets, "taxi_top_cropped1.png"),640))
    Dim  mx As MarkerExtras
  20. Erel

    Erel Administrator Staff Member Licensed User

    You should use different icons (with different sizes) and always use 160 as the multiplier.
  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