Android Tutorial OSMDroid - MapView for B4A tutorial

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

  1. cas6678

    cas6678 Active Member Licensed User

  2. tracklocator

    tracklocator Member Licensed User

    You can post the project maybe I can help you a little.
     
  3. cas6678

    cas6678 Active Member Licensed User

    Yes, thanks.

    Code:
    #Region Module Attributes
        
    #FullScreen: False
        
    #IncludeTitle: True
        
    #ApplicationLabel: MapsForgeOsmDroid38 (mapa)
        
    #VersionCode: 1
        
    #VersionName:
        
    #SupportedOrientations: unspecified
        
    #CanInstallToExternalStorage: False
    #End Region

    Sub Process_Globals
        
    Dim SavedMapStateFileName As String="map_state.dat"
        
    Dim CompassEnabled, FollowLocationEnabled, MyLocationEnabled As Boolean
        
    Dim Timer1 As Timer
    End Sub

    Sub Globals
        
    Dim MapView1 As MapView
        
    Dim ScaleBarOverlay1 As ScaleBarOverlay
        
    Dim MyLocationOverlay1 As MyLocationOverlay
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        Timer1.Initialize(
    "Timer1"5000' 5000 = 5 seconds
        Dim MapCenter As GeoPoint
        
    Dim MapsForgeTileSourceName As String="MapsForge1"
        
    Dim MapsForgeDatabaseName As String="spain.map"
        
    Dim MapsForgeDatabasePath As String=File.DirRootExternal
        
    Dim ZoomLevel As Int
        
    If File.Exists(MapsForgeDatabasePath, MapsForgeDatabaseName)=False Then
            
    File.Copy(File.DirAssets, MapsForgeDatabaseName, MapsForgeDatabasePath, MapsForgeDatabaseName)
        
    End If
        MapView1.Initialize(
    "")
        
    Dim CurrentTilesSources As List=MapView1.GetTileSources
        
    If CurrentTilesSources.IndexOf(MapsForgeTileSourceName)=-1 Then
            
    '    the MapsForgeTileSource has not been added to the MapView so create it and add it to the map
            Dim MapsForgeTileSource1 As MapsForgeTileSource
            
    '    set the required MapsForgeTileSourceOptions MapDatabaseFile and TileSourceName
            MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetMapDatabaseFile(MapsForgeDatabasePath, MapsForgeDatabaseName)
            MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetTileSourceName(MapsForgeTileSourceName)
            
    '    example of setting an optional MapsForgeTileSourceOptions
            '    MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetTextScale(2.0)
            '    now that the required MapsForgeTileSourceOptionshave been set we can call the MapsForgeTileSource Initialize method
            MapsForgeTileSource1.Initialize
            MapView1.AddTileSource(MapsForgeTileSource1)
        
    End If
        MapView1.SetMultiTouchEnabled(
    True)
        MapView1.SetTileSource(MapsForgeTileSourceName)
        MapView1.SetZoomEnabled(
    True)
        
    If File.Exists(File.DirInternal, SavedMapStateFileName) Then
            
    '    restore the saved map state
            Dim RandomAccessFile1 As RandomAccessFile
            RandomAccessFile1.Initialize(
    File.DirInternal, SavedMapStateFileName, True)
            MapCenter=RandomAccessFile1.ReadObject(
    0)
            ZoomLevel=RandomAccessFile1.ReadInt(RandomAccessFile1.CurrentPosition)
            RandomAccessFile1.Close
            MapView1.Zoom=ZoomLevel
            MapView1.SetCenter3(MapCenter)
        
    Else
            MapCenter=MapsForgeTileSource1.MapDatabase.MapFileInfo.StartPosition
            ZoomLevel=MapsForgeTileSource1.MapDatabase.MapFileInfo.StartZoomLevel
            
    If MapCenter.IsInitialized And ZoomLevel<>-1 Then
                
    '    the map database has a start position and a start zoom set
                '    we'll use that for the default map state
                MapView1.Zoom=ZoomLevel
                MapView1.SetCenter3(MapCenter)
            
    Else
                
    '    the default map state will be defined by the area covered by the map database
                MapView1.FitMapToBoundingBox(MapsForgeTileSource1.MapDatabase.MapFileInfo.BoundingBox)
            
    End If
        
    End If
        
    Activity.AddView(MapView1, 10%x10%y80%x80%y)
       
        
    Activity.AddMenuItem("Clear saved state""Menu")
        
    '    initialize and add the MyLocationOverlay to the MapView, an EventName is used as we'll be listening for all three events that this overlay generates
        MyLocationOverlay1.Initialize(MapView1, "MyLocationOverlay1")
        MapView1.AddOverlay(MyLocationOverlay1)
        
    If FirstTime Then
            
    '    set the default values for the new variables
            MyLocationOverlay1.CompassEnabled=True
            MyLocationOverlay1.MyLocationEnabled=
    True
            MyLocationOverlay1.FollowLocationEnabled=
    True
            CompassEnabled=MyLocationOverlay1.CompassEnabled
            FollowLocationEnabled=MyLocationOverlay1.FollowLocationEnabled
            MyLocationEnabled=MyLocationOverlay1.MyLocationEnabled
        
    Else
            
    '    restore the MyLocationOverlay state
            MyLocationOverlay1.CompassEnabled=CompassEnabled
            MyLocationOverlay1.FollowLocationEnabled=FollowLocationEnabled
            MyLocationOverlay1.MyLocationEnabled=MyLocationEnabled
            MyLocationOverlay1.CompassEnabled=
    True
            MyLocationOverlay1.MyLocationEnabled=
    True
            MyLocationOverlay1.FollowLocationEnabled=
    True
        
    End If
        ScaleBarOverlay1.Initialize(MapView1)
        MapView1.AddOverlay(ScaleBarOverlay1)
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
        
    '    save the current map zoom level and center
        Dim RandomAccessFile1 As RandomAccessFile
        RandomAccessFile1.Initialize(
    File.DirInternal, SavedMapStateFileName, False)
        RandomAccessFile1.WriteObject(MapView1.GetCenter, 
    True0)
        RandomAccessFile1.WriteInt(MapView1.Zoom, RandomAccessFile1.CurrentPosition)
        RandomAccessFile1.Close
            
    '    save the MyLocationOverlay state
        CompassEnabled=MyLocationOverlay1.CompassEnabled
        FollowLocationEnabled=MyLocationOverlay1.FollowLocationEnabled
        MyLocationEnabled=MyLocationOverlay1.MyLocationEnabled
        
    '    disable MyLocationOverlay compass and GPS listening
        MyLocationOverlay1.CompassEnabled=False
        MyLocationOverlay1.MyLocationEnabled=
    False
    End Sub

    Sub Menu_Click
        
    Dim Action As String=Sender
        
    Select Action
            
    Case "Clear saved state"
                
    If File.Exists(File.DirInternal, SavedMapStateFileName) Then
                    
    File.Delete(File.DirInternal, SavedMapStateFileName)
                
    End If
        
    End Select
    End Sub
    '    event listeners for the three events that MyLocationOverlay generates
    Sub MyLocationOverlay1_FollowLocationAutoDisabled
        
    Log("MyLocationOverlay1_FollowLocationAutoDisabled")
        
    '    if FollowLocation is enabled and the map is dragged then FollowLocation is automatically disabled
        'ToastMessageShow("FollowLocation is now DISABLED due to the map being dragged", False)
        Timer1.Enabled = True
    End Sub

    Sub MyLocationOverlay1_LocationChanged(NewLocation As Location, IsFirstFix As Boolean)
        
    Log("MyLocationOverlay1_LocationChanged, Latitude="&NewLocation.Latitude&", Longitude="&NewLocation.Longitude&", IsFirstFix="&IsFirstFix)
    End Sub

    Sub MyLocationOverlay1_ProviderChanged(Provider As String, Enabled As Boolean)
        
    '    note that i have yet to see this event generated
        Log("MyLocationOverlay1_ProviderChanged, Provider="&Provider&", Enabled="&Enabled)
    End Sub

    Sub Timer1_Tick
       
    'Handle tick events
        MyLocationOverlay1.CompassEnabled=True
        MyLocationOverlay1.MyLocationEnabled=
    True
        MyLocationOverlay1.FollowLocationEnabled=
    True
    End Sub
     
  4. tracklocator

    tracklocator Member Licensed User

    Please export a zip pack the project.
     
  5. cas6678

    cas6678 Active Member Licensed User

    My map is big. I have changed it by the map of Monaco that came in the example of Martin because it is smaller
     

    Attached Files:

  6. tracklocator

    tracklocator Member Licensed User

    I am not sure in some points and there is not much information about it I hope with this you can continue
    Code:
    #Region Module Attributes
        
    #FullScreen: False
        
    #IncludeTitle: True
        
    #ApplicationLabel: MapsForgeOsmDroid38 (mapa)
        
    #VersionCode: 1
        
    #VersionName:
        
    #SupportedOrientations: unspecified
        
    #CanInstallToExternalStorage: False
    #End Region

    Sub Process_Globals
        
    Dim SavedMapStateFileName As String="map_state.dat"
        
    Dim CompassEnabled, FollowLocationEnabled, MyLocationEnabled As Boolean
        
    Dim Timer1 As Timer
    End Sub

    Sub Globals
        
    Dim MapView1 As OSMDroid_MapView
        
    Dim ScaleBarOverlay1 As OSMDroid_ScaleBarOverlay
        
    Dim MyLocationOverlay1 As OSMDroid_MyLocationOverlay
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        Timer1.Initialize(
    "Timer1"5000' 5000 = 5 seconds
        Dim MapCenter As OSMDroid_GeoPoint
        
    Dim MapsForgeTileSourceName As String="MapsForge1"
        
    Dim MapsForgeDatabaseName As String="monaco.map"
        
    Dim MapsForgeDatabasePath As String=File.DirRootExternal
        
    Dim ZoomLevel As Int
        
    If File.Exists(MapsForgeDatabasePath, MapsForgeDatabaseName)=False Then
            
    File.Copy(File.DirAssets, MapsForgeDatabaseName, MapsForgeDatabasePath, MapsForgeDatabaseName)
        
    End If
        MapView1.Initialize(
    "")
        
    Dim CurrentTilesSources As List=MapView1.GetTileSources
        
    If CurrentTilesSources.IndexOf(MapsForgeTileSourceName)=-1 Then
            
    '    the MapsForgeTileSource has not been added to the MapView so create it and add it to the map
            Dim MapsForgeTileSource1 As MapsForgeTileSource
            
    '    set the required MapsForgeTileSourceOptions MapDatabaseFile and TileSourceName
            MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetMapDatabaseFile(MapsForgeDatabasePath, MapsForgeDatabaseName)
            MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetTileSourceName(MapsForgeTileSourceName)
            
    '    example of setting an optional MapsForgeTileSourceOptions
            '    MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetTextScale(2.0)
            '    now that the required MapsForgeTileSourceOptionshave been set we can call the MapsForgeTileSource Initialize method
            MapsForgeTileSource1.Initialize
            MapView1.GetTileProvider(MapsForgeTileSource1)
        
    End If
        MapView1.SetMultiTouchControls(
    True)
        MapView1.SetTileSource(MapsForgeTileSourceName)
        MapView1.SetBuiltInZoomControls(
    True)
        
    If File.Exists(File.DirInternal, SavedMapStateFileName) Then
            
    '    restore the saved map state
            Dim RandomAccessFile1 As RandomAccessFile
            RandomAccessFile1.Initialize(
    File.DirInternal, SavedMapStateFileName, True)
            MapCenter=RandomAccessFile1.ReadObject(
    0)
            ZoomLevel=RandomAccessFile1.ReadInt(RandomAccessFile1.CurrentPosition)
            RandomAccessFile1.Close
            MapView1.GetZoomLevel=ZoomLevel
            MapView1.GetMapCenter
        
    Else
            MapCenter=MapsForgeTileSource1.MapDatabase.MapFileInfo.StartPosition
            ZoomLevel=MapsForgeTileSource1.MapDatabase.MapFileInfo.StartZoomLevel
            
    If MapCenter.IsInitialized And ZoomLevel<>-1 Then
                
    '    the map database has a start position and a start zoom set
                '    we'll use that for the default map state
                MapView1.GetZoomLevel=ZoomLevel
                MapView1.GetMapCenter
            
    Else
                
    '    the default map state will be defined by the area covered by the map database
                MapView1.ZoomToBoundingBox(MapsForgeTileSource1.MapDatabase.MapFileInfo.BoundingBox)
            
    End If
        
    End If
        
    Activity.AddView(MapView1, 10%x10%y80%x80%y)
       
        
    Activity.AddMenuItem("Clear saved state""Menu")
        
    '    initialize and add the MyLocationOverlay to the MapView, an EventName is used as we'll be listening for all three events that this overlay generates
        MyLocationOverlay1.Initialize( "MyLocationOverlay1",MapView1)
        MapView1.GetOverlays.Add(MyLocationOverlay1)
        
    If FirstTime Then
            
    '    set the default values for the new variables
    '        MyLocationOverlay1.CompassEnabled=True
            MyLocationOverlay1.EnableMyLocation
            MyLocationOverlay1.EnableFollowLocation
    '        CompassEnabled=MyLocationOverlay1.CompassEnabled
            MyLocationOverlay1.EnableFollowLocation
            MyLocationOverlay1.EnableMyLocation
        
    Else
            
    '    restore the MyLocationOverlay state
            '        MyLocationOverlay1.CompassEnabled=True
            MyLocationOverlay1.EnableMyLocation
            MyLocationOverlay1.EnableFollowLocation
            
    '        CompassEnabled=MyLocationOverlay1.CompassEnabled
            MyLocationOverlay1.EnableFollowLocation
            MyLocationOverlay1.EnableMyLocation
        
    End If
        ScaleBarOverlay1.Initialize
        MapView1.GetOverlays.Add(ScaleBarOverlay1)
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
        
    '    save the current map zoom level and center
        Dim RandomAccessFile1 As RandomAccessFile
        RandomAccessFile1.Initialize(
    File.DirInternal, SavedMapStateFileName, False)
        RandomAccessFile1.WriteObject(MapView1.GetMapCenter, 
    True0)
        RandomAccessFile1.WriteInt(MapView1.GetZoomLevel, RandomAccessFile1.CurrentPosition)
        RandomAccessFile1.Close
            
    '    save the MyLocationOverlay state
    '    CompassEnabled=MyLocationOverlay1.CompassEnabled
        MyLocationOverlay1.EnableFollowLocation
        MyLocationOverlay1.EnableMyLocation
        
    '    disable MyLocationOverlay compass and GPS listening
    '    MyLocationOverlay1.CompassEnabled=False
        MyLocationOverlay1.DisableMyLocation
    End Sub

    Sub Menu_Click
        
    Dim Action As String=Sender
        
    Select Action
            
    Case "Clear saved state"
                
    If File.Exists(File.DirInternal, SavedMapStateFileName) Then
                    
    File.Delete(File.DirInternal, SavedMapStateFileName)
                
    End If
        
    End Select
    End Sub
    '    event listeners for the three events that MyLocationOverlay generates
    Sub MyLocationOverlay1_FollowLocationAutoDisabled
        
    Log("MyLocationOverlay1_FollowLocationAutoDisabled")
        
    '    if FollowLocation is enabled and the map is dragged then FollowLocation is automatically disabled
        'ToastMessageShow("FollowLocation is now DISABLED due to the map being dragged", False)
        Timer1.Enabled = True
    End Sub

    Sub MyLocationOverlay1_LocationChanged(NewLocation As Location, IsFirstFix As Boolean)
        
    Log("MyLocationOverlay1_LocationChanged, Latitude="&NewLocation.Latitude&", Longitude="&NewLocation.Longitude&", IsFirstFix="&IsFirstFix)
    End Sub

    Sub MyLocationOverlay1_ProviderChanged(Provider As String, Enabled As Boolean)
        
    '    note that i have yet to see this event generated
        Log("MyLocationOverlay1_ProviderChanged, Provider="&Provider&", Enabled="&Enabled)
    End Sub

    Sub Timer1_Tick
       
    'Handle tick events
    '    MyLocationOverlay1.CompassEnabled=True
        MyLocationOverlay1.EnableMyLocation
        MyLocationOverlay1.EnableFollowLocation
    End Sub
     
  7. Magma

    Magma Well-Known Member Licensed User

    Hi,

    in b4a...
    I was using Mapnik tiles (I was using Mobile Atlas - must use this tool or something else ? 1st - question) and OSM Droid 3.53 for personal use... i ve change mobile phone -took 5 inch better...
    but suddenly tiles of MapNik not displaying as before - it is like resolution is different (it is different!)...

    + I am trying from b4j use the same maps with osm droid - is not possible ? something for the same use (2nd-question)

    That i am telling... because i want to make an app that will be use at small phones or big or tablets and i want to use the same maps with my desktop app (i will create at b4j)...

    So from now on - what type of Tiles i must use in what res / what osmdroid / for offline (ofcourse) use ? (3-5 question)
    Is it possible to get geocoding without paying google (getting address name with no or the exactly lat/lon if now address) (6-question)
    Is it possible to get distance between lat/lon points through roads from these maps too. (7 question)

    Sorry for too many questions but i wanna update my APP and boost it (becasue is too old for my extra options)
     
  8. tracklocator

    tracklocator Member Licensed User

    Hello, I am still working on my project, I use my own map tiles server and it works very well.
    I have not done anything with Mapnik.
    In the following link are examples of the OSMDroid library I recommend using version 4.1.
    Answer first question:
    You can use it in a personal or commercial way respecting the guidelines of Apache License 2.0
    Answer second question:
    In the examples the map fits on any screen.
    Answer question 3-5
    All google services are costly if they do not meet the usage conditions.
    7.
    I am just looking at that point and I saw a project to get routes and the distance from point A and B but it is somewhat complex http://wiki.openstreetmap.org/wiki/Valhalla

    Something I've seen is that most of the sites that offer tiles and geocoding have limits that's why I've been working on my services and until now I already have my own tile server with
    Https://switch2osm.org/serving-tiles/manually-building-a-tile-server-14-04/
    Nominatim reverse Geocode
    Http://wiki.openstreetmap.org/wiki/Nininatim/Installation
    Routes and distance
    Http://wiki.openstreetmap.org/wiki/Valhalla

    And I am very enthusiastic trying to add opentraffic but I still do not succeed.

    As you realize there is a lot of way but you can achieve a good job.
     
  9. Magma

    Magma Well-Known Member Licensed User

    @tracklocator
    Thanks for the answer...

    1) Not trying to make my openstreetmap server.. i want only use local maps (like city or country) downloaded at my devices (phone, tablet) - whats the best way (app for windows) to download mapnik openstreetmap tiles to my local pc and use at my devices... what resolution i will pick...

    But i want to have latest maps and working tiles...

    2) can i use ready packs like *.shp.zip or *.osm.pbf from ex. geofabrik.de ?

    3) is continue from 2.. .can i use .map or .pbf at B4J (not b4a).. ?

    Thanks again :)
     
    Last edited: Apr 26, 2017
  10. canalrun

    canalrun Well-Known Member Licensed User

    Hello,

    I'm using OSMDroid version 3.6. It looks like this may be an older version, but it does everything I want, and it works beautifully.

    Thank you Martin.

    I am showing maps on an Android Wear Watch. There is no Wi-Fi and no cellular. I download tiles for the area I will be traveling so that I can view my location.

    Sometimes I will be viewing maps at, for example, zoom level 16, and I will travel outside the area for which I have tiles. But, I may have tiles stored on the watch for this location at zoom level 15.

    Is there any way to detect that tiles don't exist at the current zoom level but do exist for the current location at a different zoom level?

    I could then automatically switch to that zoom level.

    This is not a biggie requirement, just something that might be useful if it already exists.

    Barry.
     
  11. pompierecattivo

    pompierecattivo Member Licensed User

    Hello,
    i'm testing for b4a apps using offline sqlitedb maps. As others, i've obtained an empty screen using the example 11 provided at the fist page. I'm not sure what i have to indicate on SetTileSource (my map file's named "sardroidmap.sqlitedb"). Of couse i've placed it directly on osmdroid folder. I'm sure about my map file because i could open it correctly in a Locus GIS (beta) app. I'm using 3.0.8 ver of osmdroid.
    Any help appreciate, thank you.
    Sorry for my bad english.
     
  12. victormedranop

    victormedranop Well-Known Member Licensed User

    Someone had an example -> updating location from a service?
    and redraw the mapview?

    thanks

    Victor
     
  13. DonManfred

    DonManfred Expert Licensed User

    Code:
    dim point as geopoint
    point.Initialize(52.751920.40505)
    MapView1.SetCenter3(
    point)
     
    victormedranop likes this.
  14. victormedranop

    victormedranop Well-Known Member Licensed User

    what version od osmGroid are you using? i'm using 4_1.
    and does not have

    Code:
    MapView1.SetCenter3(point)
     
  15. DonManfred

    DonManfred Expert Licensed User

    i´m not using OSM at all.
    I just searched for example code in the OSM thread and posted my finding.

    Maybe this is only in OSM 3 available. You need to check what OSM 4.1 is providing and use this.
     
  16. js486dog

    js486dog Member Licensed User

    Maybe this one:

    Code:
    Sub Process_Globals
        
    Dim MapCenter As OSMDroid_GeoPoint
    End Sub

    Sub Activity_Create(FirstTime As Boolean)

    lat_deg=
    49.106214
    lon_deg=
    18.926182
    MapCenter.Initialize(lat_deg, lon_deg)

    MapView1.GetController.SetCenter(MapCenter)

    End Sub
     
    victormedranop likes this.
  17. jamesnz

    jamesnz Active Member Licensed User

    Can anyone confirm that OSMDroid_4_1 (Version (0.04)
    and OSMDroid_4_1_MapsForgeTileSource are the only libraries required ?
    my code below ( Martins - MapsForgeTileSource) does not recognise the MapView
    This did work when using 3_08

    Code:
    #Region Module Attributes
        
    #FullScreen: False
        
    #IncludeTitle: True
        
    #ApplicationLabel: MapsForgeTileSource
        
    #VersionCode: 1
        
    #VersionName:
        
    #SupportedOrientations: unspecified
        
    #CanInstallToExternalStorage: False
    #End Region

    Sub Process_Globals
        
    Dim SavedMapStateFileName As String="map_state.dat"
    End Sub

    Sub Globals
        
    Dim MapView1 As MapView
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    Dim MapCenter As GeoPoint
        
    Dim MapsForgeTileSourceName As String="MapsForge1"
        
    Dim MapsForgeDatabaseName As String="monaco.map"
        
    Dim MapsForgeDatabasePath As String=File.DirRootExternal
        
    Dim ZoomLevel As Int
        
        
    If File.Exists(MapsForgeDatabasePath, MapsForgeDatabaseName)=False Then
            
    File.Copy(File.DirAssets, MapsForgeDatabaseName, MapsForgeDatabasePath, MapsForgeDatabaseName)
        
    End If

        MapView1.Initialize(
    "")
        
        
    Dim CurrentTilesSources As List=MapView1.GetTileSources
        
    If CurrentTilesSources.IndexOf(MapsForgeTileSourceName)=-1 Then
            
    '    the MapsForgeTileSource has not been added to the MapView so create it and add it to the map
            
            
    Dim MapsForgeTileSource1 As MapsForgeTileSource
            
    '    set the required MapsForgeTileSourceOptions MapDatabaseFile and TileSourceName
            MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetMapDatabaseFile(MapsForgeDatabasePath, MapsForgeDatabaseName)
            MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetTileSourceName(MapsForgeTileSourceName)
            
            
    '    example of setting an optional MapsForgeTileSourceOptions
            '    MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetTextScale(2.0)
            
            
    '    now that the required MapsForgeTileSourceOptionshave been set we can call the MapsForgeTileSource Initialize method
            MapsForgeTileSource1.Initialize
            MapView1.AddTileSource(MapsForgeTileSource1)
        
    End If
        
        MapView1.SetMultiTouchEnabled(
    True)
        MapView1.SetTileSource(MapsForgeTileSourceName)
        MapView1.SetZoomEnabled(
    True)
        
        
    If File.Exists(File.DirInternal, SavedMapStateFileName) Then
            
    '    restore the saved map state
            Dim RandomAccessFile1 As RandomAccessFile
            RandomAccessFile1.Initialize(
    File.DirInternal, SavedMapStateFileName, True)
            MapCenter=RandomAccessFile1.ReadObject(
    0)
            ZoomLevel=RandomAccessFile1.ReadInt(RandomAccessFile1.CurrentPosition)
            RandomAccessFile1.Close
            MapView1.Zoom=ZoomLevel
            MapView1.SetCenter3(MapCenter)
        
    Else
            MapCenter=MapsForgeTileSource1.MapDatabase.MapFileInfo.StartPosition
            ZoomLevel=MapsForgeTileSource1.MapDatabase.MapFileInfo.StartZoomLevel
            
    If MapCenter.IsInitialized And ZoomLevel<>-1 Then
                
    '    the map database has a start position and a start zoom set
                '    we'll use that for the default map state
                MapView1.Zoom=ZoomLevel
                MapView1.SetCenter3(MapCenter)
            
    Else
                
    '    the default map state will be defined by the area covered by the map database
                MapView1.FitMapToBoundingBox(MapsForgeTileSource1.MapDatabase.MapFileInfo.BoundingBox)
            
    End If
        
    End If
        
        
    Activity.AddView(MapView1, 00100%x100%y)
        
        
    Activity.AddMenuItem("Clear saved state""Menu")
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
        
    '    save the current map zoom level and center
        Dim RandomAccessFile1 As RandomAccessFile
        RandomAccessFile1.Initialize(
    File.DirInternal, SavedMapStateFileName, False)
        RandomAccessFile1.WriteObject(MapView1.GetCenter, 
    True0)
        RandomAccessFile1.WriteInt(MapView1.Zoom, RandomAccessFile1.CurrentPosition)
        RandomAccessFile1.Close
    End Sub

    Sub Menu_Click
        
    Dim Action As String=Sender
        
    Select Action
            
    Case "Clear saved state"
                
    If File.Exists(File.DirInternal, SavedMapStateFileName) Then
                    
    File.Delete(File.DirInternal, SavedMapStateFileName)
                
    End If
        
    End Select
    End Sub
     
  18. PABLO2013

    PABLO2013 Active Member Licensed User

    jamesnz
    Saludos.
    Add app permissions storage.
     
    jamesnz likes this.
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