Android Tutorial OSMDroid - MapView for B4A tutorial

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

  1. warwound

    warwound Expert Licensed User

    @Sam H

    I put a few example together for version 4.1 and these can be found here: http://b4a.martinpearman.co.uk/osmdroid/OSMDroid_v4.1_examples.zip.
    Unfortunately i didn't (and don't) have time to create some real tutorials for version 4.1 as i did for version 3.0.8 :(.

    If you can't get your project to work then export your project as a zip file and post it to the forum and i'll help debug it.

    Martin.
     
  2. Sam H

    Sam H Member Licensed User

  3. warwound

    warwound Expert Licensed User

  4. Sam H

    Sam H Member Licensed User

    Ok, not to worry, do you have an example of the TileSourceSpinner using OSMDroid_4_1 as I can only find the one for the older version which I can't get to work since Mapview1.SetTileSource() requires an Object rather than a string "" like the old version.

    How would I define "mapnik", "CycleMap", "OSMPublicTransport", "MapquestOSM" etc. as OSMDroid_MapTile's?

    Thanks

    Sam
     
  5. warwound

    warwound Expert Licensed User

    @Sam H

    Attached is the updated 'select a TileSource' demo, updated to work with OSMDroid 4.1.
    Tested and working here on my Moto G (KitKat).

    Code:
    Sub Process_Globals
        
    Dim InitialTileSourceName As String="Mapnik"
        
    Dim MapCenter As OSMDroid_GeoPoint
        
    Dim SelectedTileSource As OSMDroid_TileSource
        
    Dim ZoomLevel As Int
    End Sub

    Sub Globals
        
    Dim MapView1 As OSMDroid_MapView
        
    Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
        
    Dim TileSourceSpinner As Spinner
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    If FirstTime Then
            MapCenter.Initialize(
    52.751920.40505)
            ZoomLevel=
    14
            
            
    '    set the default initial TileSource
            SelectedTileSource=TileSourceFactory1.GetTileSource(InitialTileSourceName)
        
    End If
        
        MapView1.Initialize(
    "")
        
        MapView1.SetBuiltInZoomControls(
    True)
        MapView1.SetMultiTouchControls(
    True)
        
        MapView1.GetController.SetZoom(ZoomLevel)
        MapView1.GetController.SetCenter(MapCenter)
        
        
    Activity.AddView(MapView1, 048dip100%x100%y-48dip)
        
        TileSourceSpinner.Initialize(
    "TileSourceSelect")
        
        
    Dim TileSourceFactory1 As OSMDroid_TileSourceFactory
        
    Dim AvailableTileSources() As OSMDroid_TileSource
        AvailableTileSources=TileSourceFactory1.GetTileSources
        
        
    For Each AvailableTileSource As OSMDroid_TileSource In AvailableTileSources
            TileSourceSpinner.Add(AvailableTileSource.Name)
        
    Next
        
        TileSourceSpinner.Prompt=
    "Select a TileSource"
        TileSourceSpinner.SelectedIndex=TileSourceSpinner.IndexOf(SelectedTileSource.Name)
        
    Activity.AddView(TileSourceSpinner, 00100%x48dip)
        
        
    '    manually call the Spinner ItemClick Sub to sync the MapView TileSource with the spinner SelectedIndex
        TileSourceSelect_ItemClick(TileSourceSpinner.SelectedIndex, TileSourceSpinner.SelectedItem)
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
        MapCenter=MapView1.GetMapCenter
        ZoomLevel=MapView1.GetZoomLevel
    End Sub

    Sub TileSourceSelect_ItemClick (Position As Int, Value As Object)
        
    '    set the MapView TileSource
        Dim TileSourceName As String=Value
        SelectedTileSource=TileSourceFactory1.GetTileSource(TileSourceName)
        MapView1.SetTileSource(SelectedTileSource)
    End Sub
    Martin.
     

    Attached Files:

  6. Sam H

    Sam H Member Licensed User

    Thanks again for such a quick response, I have got it working on my Nexus 7 (Android Jelly Bean). Some of the tileSources that are displayed on the spinner such as "base", "topo" and "hills" don't show anything, although I was able to remove them.

    Thanks

    Sam
     
    warwound likes this.
  7. PABLO2013

    PABLO2013 Active Member Licensed User

    greetings martin
    few weeks back , i post to how how could see the scala overlay again in my projects ... I can not make it look ... I have followed the forum about it can be a problem in the manifest file, but do not I can fix, I use windows 7, jdk1.7.0_67 \ bin \ javac.exe, android-10 \ android.jar, osm 3.6 (I tried 4.0 with no result) B4A 3.82, tks , plz helpme.
     
  8. jamesnz

    jamesnz Active Member Licensed User

    Is there a possibility of setting up a custom tile server. I have made customised tiles ( way too many to store on device) . How would one store these on a web server and have the mapview make the appropriate requests. I'm presuming I could set up a directory on my server and designthe file structure the same as the x/y calls
     
  9. warwound

    warwound Expert Licensed User

    How are your customised tiles named?
    Are they named using the slippy map tile naming convention:

    folder named after zoom level > folder named after tile x parameter > tile named after tile y parameter.

    If so move all the folders named after the zoom level to a single new folder.
    Now add this new folder to a new zip archive and upload it to your server.
    Your server hopefully has a control panel where you can now unzip the archive.

    Nothing special needs to be done, just establish the path to the un-zipped tiles on your server and update your OSMDroid code to use the online custom tiles.

    If your server has no way for you to unzip an archive then you'll have to upload all your custom tiles one by one using FTP and that will take a long while if you have lots of tiles.

    Martin.
     
  10. jamesnz

    jamesnz Active Member Licensed User

    yes , I just use the standard slippymap convention.( tiles made by maperative ).png
    Question was how to tell the mapview what my server address is eg "www.myserver.co.nz/mymaptiles"/x/y/etc
    I assume I have to change the tile source factory to a custom address somehow ?
     
  11. warwound

    warwound Expert Licensed User

    Which version of OSMDroid are you using?
    Version 3.0.8 or 4.1?

    Martin.
     
  12. jamesnz

    jamesnz Active Member Licensed User

    4.1
     
  13. warwound

    warwound Expert Licensed User

  14. jamesnz

    jamesnz Active Member Licensed User

  15. warwound

    warwound Expert Licensed User

  16. jamesnz

    jamesnz Active Member Licensed User

    I have zoom 18 tiles so I just changed the maximum zoom in the mytilesource.initialize to 0,18,256
    works fine - and I'm still ftping to the server :)
    cheers for the help :)
     
    warwound likes this.
  17. PABLO2013

    PABLO2013 Active Member Licensed User

    greetings martin
    few weeks back , i post to how how could see the scala overlay again in my projects ... I can not make it look ... I have followed the forum about it can be a problem in the manifest file, but do not I can fix, I use windows 7, jdk1.7.0_67 \ bin \ javac.exe, android-10 \ android.jar, osm 3.6 (I tried 4.0 with no result) B4A 3.82, tks , plz helpme.
     
  18. georm

    georm Member Licensed User

    Hello
    About OSMDroid_UrlTileSource. I'd use the server tiles from IGN (French service). The url use a key, i's not a problem, but use an authentication with user and password.
    When I program in Microsoft .Net. I use a HttpWebRequest object with a NetworkCredential to pass the User and the Password.
    Is there a equivalence en b4a, I'm a beginner.
    Sample IGN url:

    Code:
    https://gpp3-wxs.ign.fr/my_ignkey/wmts?LAYER=ORTHOIMAGERY.ORTHOPHOTOS&EXCEPTIONS=text/xml&FORMAT=image/jpeg&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&STYLE=normal&TILEMATRIXSET=PM&TILEMATRIX=18&TILEROW=90241&TILECOL=132877
    Thanks
    Laurent
     
  19. warwound

    warwound Expert Licensed User

    @georm

    Are you saying that you send the auth username and password to the tileserver using an HTTP request and you get a 'token' back.
    And then when you request a tile, that token must be part of the tile request url?
     
  20. georm

    georm Member Licensed User

    I must just use HTTP with ExecuteCredentials and pass a httpRequest with username and password and recup the taskid ?

    Thanks
     
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