Android Tutorial OSMDroid - MapView for B4A tutorial

Discussion in 'Tutorials & Examples' started by warwound, Mar 26, 2012.

  1. warwound

    warwound Expert Licensed User


    To be honest i'm not sure but i think that's what i'd try.
  2. georm

    georm Member Licensed User

    Ok, i' try and i will inform you

  3. jamesnz

    jamesnz Active Member Licensed User

    Just an idea I had re tile servers.
    You can initialise a mapview and tile server based on your location.
    eg if you have a custom tile server that covers a small area you can test that users device is 'outside' this area and use the standard OSM tile server, if inside the area you can use your own tile server. This solves the problem of having to host millions of tiles that are irrelevant to your needs.
  4. TAK

    TAK Member Licensed User

    is there an example for a navigation?
  5. warwound

    warwound Expert Licensed User

    OSMDroid has no navigation features :(.
    In fact b4a lacks any navigation library - you'll have to implement your own.
    Use HttpUtils2 and a web service such as Google's:

    TAK likes this.
  6. georm

    georm Member Licensed User

    I want to add a new TileSource just Offline, never online. Is-it possible ?

  7. warwound

    warwound Expert Licensed User

    Search the forum for MapsForgeTileSource.

  8. georm

    georm Member Licensed User

    Very interesting for vector map, but for raster tiles.

  9. warwound

    warwound Expert Licensed User

    You want offline raster tiles?
    That is possible, search the forum for MBTiles, MOBAC and Mobile Atlas Creator.
  10. georm

    georm Member Licensed User

    I generated a set of zip tiles like and i want to use always offline.

  11. TAK

    TAK Member Licensed User

    what i have to do, if i want use Compass, ScaleBar, Spinner...? If i only copy the code, its doesnt work.
  12. warwound

    warwound Expert Licensed User

    You need to experiment with the manifest file.
    Targeting an android api version of Honeycomb and newer and adding the android:hardwareAccelerated="false" attribute to the application element should work.

    Have a look at this page:

    • The activity that displays the MapView needs hardware acceleration disabled.
    • Hardware acceleration is enabled by default for all activities in your application if your Target API level is >=14.
    • Hardware acceleration can be enabled or disabled for all activities or single activities using the manifest.
    • Hardware acceleration can also be disabled using code, this java method disables hardware acceleration for the MapView only:
      private void setHardwareAccelerationOff() {
      View.LAYER_TYPE_SOFTWARE, null);
      You can probably use JavaObject to execute this java and that would mean you don't have to modify the manifest.

    TAK likes this.
  13. davelew1s

    davelew1s Active Member Licensed User

    I've been through this thread but cannot find what I'm looking for .... I'm using ver 4.1.
    I have an app which works ok what I want to do now is hide the map and replace it with a black screen, so that
    I can put a pathsoverlay on and draw some shapes in white. I need to be able to switch back and forward.
    Any help would be appreciated. Thanks Dave.
  14. warwound

    warwound Expert Licensed User

    I'd try a custom tile layer and use the same image for each and every tile.
    A 256 pixel square black PNG is all you need.

    Have a look thru the examples i uploaded to here:
    I'm sure there's a custom tile example in there somewhere.

  15. davelew1s

    davelew1s Active Member Licensed User

    Hi Martin!
    Sorry to be a pain ...... but I cannot find anything in the link you provided, I've also checked this thread again with no luck. I know you are busy but can you offer any further pointers?
    Thanks Dave.
  16. warwound

    warwound Expert Licensed User

    I'll take a look in the morning.
  17. warwound

    warwound Expert Licensed User

    I've spent the moring trying to create a new TileSource that'd allow you to use a local (file based) tile instead of an online tile.
    I just couldn't get it to work.

    So another solution is this:

    Sub Process_Globals
    Dim Constants1 As OSMDroid_Constants
    End Sub

    Sub Globals
    Dim InitialGeoPoint As OSMDroid_GeoPoint
    Dim MapView1 As OSMDroid_MapView
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    '    check the manifest for edits made re hardware acceleration
    Dim MyTileSourceName As String="MyTileSourceName"
    Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
    If Not(TileSourceFactory1.ContainsTileSource(MyTileSourceName)) Then
    Dim MyTileSource As OSMDroid_UrlTileSource
            MyTileSource.Initialize(MapView1, MyTileSourceName, 
    End If
    '    now set the initial view
        '    set the zoom before the center
    Activity.AddView(MapView1, 0,0100%x100%y)
    End Sub

    Sub Activity_Resume
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
    End Sub
    I created a plain black 256 pixel square tile and uploaded it to my server.
    Then created a UrlTileSource which fetches this plain black tile for all map tiles.

    It works but has one disadvantage...
    OSMDroid will automatically cache all tiles to the external memory - that cant be prevented.
    So your device will end up with this plain black tile cached many times, each time with a different filename.

    Run the attached example then pan and zoom the map.
    Now use a file manager app to browse on your device to the external memory, look for the path osmdroid/tiles/MyTileSourceName.
    In that folder you'll find the black tile cached with a different file name for each time it's been used on the map.
    Guess you could run a 'cleanup' within your app to delete these cached black tiles?


    Attached Files:

  18. davelew1s

    davelew1s Active Member Licensed User

    Thanks Martin! you can't blacker than that ... I'm working on it ....will let you know the results.
  19. GaNdAlF89

    GaNdAlF89 Active Member Licensed User

    Hi, I have a question: I want to block the mapview (to always show the same position in the map) but I need the markers_click event to open info about the marker clicked.
    How can I do this? Thanks
    Last edited: Dec 18, 2014
  20. TAK

    TAK Member Licensed User

    Hi Martin,
    on which place do I have to paste this code?
  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