Android Tutorial OSMDroid - MapView for B4A tutorial

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

  1. nemiroG1

    nemiroG1 Member Licensed User

    Martin,
    OK, I finally managed to try the URLTileSource for OSMDroid 4.1, and taking that, and combining it with the XML data you posted above worked straight off! Thank you! For reference, here is the code (not that it is hard to figure out) to use aviation sectional maps (US Only at this time):

    Code:
    Version=4.2
    IconFile=
    NumberOfModules=
    0
    Build1=Default,uk.co.martinpearman.b4a.osmdroiddemo
    DoNotOverwriteManifest=
    False
    ManifestCode=
    'This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: http://www.basic4ppc.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>~\n~<supports-screens android:largeScreens="true" ~\n~    android:normalScreens="true" ~\n~    android:smallScreens="true" ~\n~    android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~'End of default text.~\n~~\n~'    required for ScaleBarOverlay?~\n~SetApplicationAttribute(android:hardwareAccelerated, "false")
    NumberOfFiles=0
    NumberOfLibraries=
    2
    Library1=core
    Library2=osmdroid_4_1
    @EndOfDesignText@
    #Region  Project Attributes 
        
    #ApplicationLabel: OSMDroid demo
        
    #VersionCode: 1
        
    #VersionName
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: unspecified
        
    #CanInstallToExternalStorage: False
    #End Region

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

    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
       
        MapView1.Initialize(
    "")
       
        
    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, 
    "http://wms.chartbundle.com/tms/v1.0/sec/%3$d/%1$d/%2$d.png?type=google"016256)
            TileSourceFactory1.AddTileSource(MyTileSource)
        
    End If
       
        MapView1.SetTileSource(TileSourceFactory1.GetTileSource(MyTileSourceName))
       
        MapView1.GetOverlayManager.GetTilesOverlay.SetLoadingBackgroundColor(
    Colors.Green)
        MapView1.GetOverlayManager.GetTilesOverlay.SetLoadingLineColor(
    Colors.Red)
        MapView1.SetBuiltInZoomControls(
    True)
        MapView1.SetMultiTouchControls(
    True)
       
        
    '    now set the initial view
        '    set the zoom before the center
        InitialGeoPoint.Initialize(52.752400.4040)
        MapView1.GetController.SetZoom(
    12)
        MapView1.GetController.SetCenter(InitialGeoPoint)
       
        
    Activity.AddView(MapView1, 0,0100%x100%y)
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub
     
  2. jsk001

    jsk001 Member Licensed User

    ...Is there a way to display the marker info immediately (without clicking) ???


     
  3. shashkiranr

    shashkiranr Active Member Licensed User

    Hi Warwound,

    I want to create an offiline map. I am using MOBAC but i am not able to download for mapnik as they have removed the support to download. Is there any way i can download and create the files for osm?

    Regards,
    SK
     
  4. warwound

    warwound Expert Licensed User

    Take a look here:
    https://switch2osm.org/serving-tiles/

    You could set up your own tile server and connect to your tile server with MOBAC.

    If you don't have a linux box available I'd suggest using VirtualBox to create a virtual Ubuntu 12.04 box.
    Install the packages: https://switch2osm.org/serving-tiles/building-a-tile-server-from-packages/
    Then download the binary map data and you can then generate your own tiles.
     
  5. shashkiranr

    shashkiranr Active Member Licensed User

    Thank you :) i will try it out and let you know the result.
     
  6. Carlo2015

    Carlo2015 Member Licensed User

    hi! Im new to b4a and I am impressed with its capabilities. and to you warwound for this great lib.

    now my question is can I use this http://download.geofabrik.de/asia.html with your library? and if yes then can you please show some example?

    when i browsed the folder where the tiles are found the format of the files are in .png.tile but the file from the above link is in pbf and it says "suitable for Osmium, Osmosis, imposm, osm2pgsql, mkgmap, and others".

    I am confused about this one.

    Or can you please give me a link where I can download mapnik tiles for asia or just for the Phlippines?

    I need to let my users have it preinstalled before they went on their way.

    Thanks

    Edit: Im now experimenting with Mobile Atlas Creator. Will ask more questions if I hit a wall again.
     
    Last edited: Apr 25, 2015
  7. warwound

    warwound Expert Licensed User

    @Carlo2015

    There links to .osm.pbf file on the Geofabrik page and you can download these and display them offline on either OSMDroid or GoogleMaps.
    Search the forum for MapsforgeTileSource (for OSMDroid) and MapsForgeTileProvider (GoogleMaps).

    These .osm.pbf files are binary databases containing Open Street Map data and are far smaller in size than an equivalent 'offline tile archive' created by MOBAC which would contains 1000s of tile images.
     
  8. Carlo2015

    Carlo2015 Member Licensed User

    warwound thanks for the fast reply, I was able to download maps for OSMPublicTransport but the files inside the folders(zip) are just .png whereas the files created by your examples are in .png.tile

    I am more confused now. :)

    Anyway I'm no way near giving up.
     
    Last edited: Apr 25, 2015
  9. warwound

    warwound Expert Licensed User

    .png and .png.tile are identical...

    I think that naming a .png to .png.tile simply prevents the android media scanner finding the tile images and so prevents the tile images from appearing in the device's Gallery.
     
    Johan Schoeman and Carlo2015 like this.
  10. Carlo2015

    Carlo2015 Member Licensed User

    Great!

    I am currently fetchng tiles for the whole Philippines. I will just use a windows application to rename all png in the folder.

    I will update here for the results.


    Thanks.
     
  11. warwound

    warwound Expert Licensed User

    http://download.geofabrik.de/asia.html
    See the .oms.pbf binary data for the entire Philippines is 'just' 111MBs?
    Once converted from .osm.pbf format to the MapsForge .map format that's likely to be around 60MBs.

    So your choice is to have either:
    • A (massive) tile archive containing many .png tile images.
      This will look best on the device - the tiles should be quick to load.
      Coverage of different areas and zoom levels will depend entirely on what tile images you have in your tile archive.
      The tile archive will likely be far larger than 60MBs.
    • A single MapsForge binary database of around 60MBs.
      Rendering map tiles on the fly on the device is a single threaded solution.
      So when your map requires tiles they get queued and rendered one at a time.
      That results in a not so good user experience - not as good as an offline tile archive.
      But the MapsForge .map file will give you coverage of the entire Philippines at all zoom levels.

    I've downloaded and am converting the Philippines .osm.pbf file to MapsForge .map format now and i'll post again when the conversion is complete.
    You can compare an offline tile archive to a MapsForge binary database and choose which one to use.

    Martin.
     
  12. warwound

    warwound Expert Licensed User

    The Philippines .osm.pbf file converted to a MapsForge .map database of 111Mbs in size.
    Normally the conversion results in a much smaller file but i guess with all the coastline data for the Philippines, the file size didn't reduce.

    You can download the Philippines MapsForge .map file here:
    http://b4a.martinpearman.co.uk/osmdroid/philippines.map.zip

    Can you let me know when you have downloaded it - i'll then delete it from my server.

    Thanks.
     
  13. Carlo2015

    Carlo2015 Member Licensed User

    Many thanks for the support.

    I have it now and you can delete it anytime.
     
  14. rayofcumbria

    rayofcumbria Member Licensed User

    Hi SK, try here for offline maps
    http://download.mapsforge.org/maps/

    here's how I load them too:
    ' OSM 4.1 library used
    Private osmMaps As OSMDroid_MapView
    Private MFTSrc As MapsForgeTileSource

    MFTSrc.GetMapsForgeTileSourceOptions.SetMapDatabaseFile(File.DirRootExternal, "mapname.map")
    MFTSrc.GetMapsForgeTileSourceOptions.SetTileSourceName("MyOwnMap")
    MFTSrc.Initialize

    osmMaps.Initialize("osmMap")

    osmMaps.SetUseDataConnection(True)
    osmMaps.SetTileSource(MFTSrc)
     
    Last edited: May 20, 2015
  15. rayofcumbria

    rayofcumbria Member Licensed User

    thanks, done that but it moves too frequently based on gps movement
     
  16. warwound

    warwound Expert Licensed User

    You'll have to implement some sort of 'smoothing' algorithm into your code to smooth/normalize the changes in orientation.
    Not sure what technique is required though.
     
  17. G-ShadoW

    G-ShadoW Active Member Licensed User

    how to change personicon as android.graphics.bitmap
    MyLocationOverlay1.PersonIcon ?
     
  18. Tom1s

    Tom1s Member Licensed User

    I couldn't find osmroid 4.1 mapsforgetilesource example ? Is the older one still working with 4.1?
     
  19. Tom1s

    Tom1s Member Licensed User

    I got it working. It works with Activity.AddView(MapView1, 0,0, 100%x, 100%y)
    Not with panel7.AddView(MapView1, 0,0, 100%x, 100%y)

    Is it possible to use it somehow like this:
    Activity.LoadLayout("Pagemain") 'containts actionbar and pcontent

    pContent.LoadLayout("page1")'contains panels

    pContent.AddView(MapView1, 0,0, 100%x, 100%y) ' this works one time. I have a menu and i like to switch between panels and this map?

    Removeviews and then again?
     
    Last edited: Jun 23, 2015
  20. Tom1s

    Tom1s Member Licensed User

    How this can be made?
    upload_2015-6-25_20-58-22.png
     
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