POI on Gooble Map View

BarrySumpter

Active Member
Licensed User
Longtime User
Hi all,

Claus and Martin,

Would either of you happen to have a way to mark store locations on either of the map samples we've been working with.

My lady has my HD2 with miui and the Coles Express won't install.

She's been driving me mad trying to find a Coles Express as she travels quite a bit.

If not then any help in the right direction would be greatly appreciated.

The .csv is in this format:


B4X:
145.0763, -37.863, "Ashburton"    
153.0163, -27.3595, "Aspley" 
etc.
 

Attachments

  • ColesExpressPOI-CSV.zip
    11.5 KB · Views: 266

BarrySumpter

Active Member
Licensed User
Longtime User
POIs within a 5k radious

POIs within a 5k radious

The csv from Coles Express in longitute, Latitude, Name order. Grrrr

B4X:
'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Dim GPS1 As GPS


End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim filefrom As FileDialog

    Dim Btn As Button    
    Dim Btn2 As Button    
    Dim Btn3 As Button    
    Dim Btn4 As Button    
    
    Dim lblPath As Label        
  Dim lblFileName As Label        

    filefrom.FilePath = "/mnt/sdcard/download"

Dim Table1, Table2 As Table


    Dim lblLat As Label
    Dim lblLng As Label

  Dim Map1 As Map

End Sub

Sub Activity_Create(FirstTime As Boolean)

    If FirstTime Then
        GPS1.Initialize("GPS")
  End If


    Btn.Initialize("btn")
    Btn2.Initialize("btn2")
    Btn3.Initialize("btn3")
  Btn4.Initialize("btn4")

    lblPath.Initialize("")
    lblFileName.Initialize("")

    lblLat.Initialize("")
    lblLng.Initialize("")

    Table1.Initialize(Me, "Table1", 4)
  Table2.Initialize(Me, "Table1", 4)

    
    
    Activity.AddView(Btn,0,0,150,100)
    Activity.AddView(Btn2,160,0,150,100)
    Activity.AddView(Btn3,320,0,150,100)
    
    Btn.Text = "Dirs to Log"
    Btn2.Text = "FileDLG"
    Btn3.Text = "Files on Download"
    Btn4.Text = "Import csv file"
    Btn4.Enabled = False
    
    Activity.AddView(lblPath, 0, 110, 100%x, 40dip)
  Activity.AddView(lblFileName, 0, 160, 100%x, 40dip)
    Activity.AddView(lblLat, 0, 190, 100%x, 40dip)
  Activity.AddView(lblLng, 0, 220, 100%x, 40dip)

    Activity.AddView(Btn4,0,100%y - 100,150,100)
    
    
    Table1.AddToActivity(Activity, 500, 260, 100%x, 50%y)    
    Table2.AddToActivity(Activity, 0, 260, 100%x, 50%y)    
    
    Table1.SetHeader(Array As String("Row", "Lat", "lng", "Name"))
    For i = 0 To 50
        Table1.AddRow(Array As String(i, "Col1", "Col2", "Col3"))
    Next

    Table2.SetHeader(Array As String("Lat", "lng", "Name", "< 5km"))
    
    Table1.SetColumnsWidths(Array As Int(70dip, 60dip, 160dip, 160dip))
    Table2.SetColumnsWidths(Array As Int(70dip, 70dip, 110dip, 60dip))


End Sub

Sub Activity_Resume
    If GPS1.GPSEnabled = False Then
        ToastMessageShow("Please enable the GPS device.", True)
        StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
    Else
        GPS1.Start(0, 0) 'Listen to GPS with no filters.
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    GPS1.Stop
End Sub

Sub btn_click

Log("File.DirAssets="&File.DirAssets)
Log("File.DirDefaultExternal="&File.DirDefaultExternal)
Log("File.DirInternal="&File.DirInternal)
Log("File.DirInternalCache="&File.DirInternalCache)
Log("File.DirRootExternal="&File.DirRootExternal)

End Sub

Sub btn2_click
    
'filefrom.Show("List of csv files", "", "", "", Null)
    Dim fd As FileDialog
    fd.FastScroll = True
    
    'fd.ShowOnlyFolders = True
    'fd.FilePath = File.DirRootExternal ' also sets ChosenName to an emtpy string
    'fd.ShowOnlyFolders = true
    'fd.FileFilter = ".txt" ' for example or ".jpg,.png" for multiple file types
        fd.FilePath = "/mnt/sdcard/download"
    fd.FileFilter = ".xls" '  ".txt" ' for example or ".jpg,.png" for multiple file types
    ret = fd.Show("B4A File Dialog", "Yes", "No", "Maybe", Null)    

        lblPath.text = fd.FilePath
        lblFileName.text = fd.ChosenName

End Sub
Sub btn3_click
    
    filefrom.FilePath = "/mnt/sdcard/download"

    'filefrom.FileFilter = ".csv"
    filefrom.FileFilter = ".xls"
    filefrom.Show("List of csv files",  "OK", "Cancel",  "", Null)
        
        lblPath.text = filefrom.FilePath
        lblFileName.text = filefrom.ChosenName
        
        
End Sub

Sub Btn4_click

    Table1.LoadTableFromCSV(lblPath.Text, lblFileName.Text, True)

    Dim MyLocation As Location
    Dim Location1 As Location

Log("a")
  
    Dim myLocationCircle As Circle
    MyLocation.Initialize2(lblLat.Text, lblLng.Text)

    myLocationCircle.Initialize(MyLocation, 5000)
  Log("b")
    Log(MyLocation.Latitude)
  Log(MyLocation.Longitude)
    Dim LocationName As String
    Dim i As Int
    Try
    Log("c")
  
            For r = 0 To 1000
'            Log(r)
'            Log(Table1.GetValue(0, r))
'            Log(Table1.GetValue(1,r))
'            Log(Table1.GetValue(2,r))

                Location1.Initialize2(Table1.GetValue(1, r), Table1.GetValue(0, r))
'            Log(Location1.Latitude)
'                Log(Location1.Longitude)
'            
'                Log(Location1)

                LocationName = Table1.GetValue(2,r)

            Log("myLoc: " & myLocationCircle.Contains(Location1))

                If myLocationCircle.Contains(Location1) Then
                    Log("adding: " & r)
                     Table2.AddRow(Array As String(Location1.Latitude, Location1.Longitude, LocationName, True))
                End If

            Next 
        Catch
        Log(LastException.Message)
        End Try


'    Table2.visible = True
'    Table1.visible = False

                     Table2.AddRow(Array As String("Done", "", "", ""))

End Sub

Sub Table1_CellClick (Col As Int, Row As Int)
    Log("CellClick: " & Col & " , " & Row)
    Activity.Title = Table1.GetValue(Col, Row)
End Sub

Sub Table1_HeaderClick (Col As Int)
    Log("HeaderClick: " & Col)
End Sub

Sub GPS_LocationChanged (Location1 As Location)

  Dim dt As String
    Dim now As Long
  
    DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss"
    
    now = DateTime.now
    dt = DateTime.Date(now)

'    lblLat.Text = "Lat = " & Location1.Latitude 
'    lblLng.Text = "Lon = " & Location1.Longitude
    lblLat.Text = Location1.Latitude 
    lblLng.Text = Location1.Longitude

If Btn4.Enabled = False Then
    Btn4.Enabled = True
End If

GPS1.Stop

End Sub

Sub GPS_UserEnabled (Enabled As Boolean)
    ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Running out of energy so notes to self:
Lots of head way today.
Never used csv
Never used tables
Most of the time spent on research and taking full advantage of the brilliant libraries and sample projects. :sign0188:

----

Map 15 - BalloonMarkers

B4X:
Sub Process_Globals
    '     a Marker is not an Activity object so can be created as a Process_Global
    '     the Markers will need to be declared as Process_Globals so we can identify and restore the open Balloon on orientation change
    Dim FocusedMarker, Marker0, Marker1, Marker2, Marker3 As Marker
    
    '    we'll use the new BalloonMarker object for Marker4
    Dim Marker4 As BalloonMarker
    
    Dim MapCenter As GeoPoint
    Dim TileSource As String
    Dim ZoomLevel As Int
End Sub

Sub Globals
    Dim MapView1 As MapView
    Dim TileSourceSpinner As Spinner
    
    '    create the MarkersBalloonOverlay
    Dim MarkersBalloonOverlay1 As MarkersBalloonOverlay
End Sub

Sub Activity_Create(FirstTime As Boolean)

    Activity.AddMenuItem("Fit Map to Markers", "FitMap")
    '    MapView initialized with no EventName as we'll not be listening for MapView events
    MapView1.Initialize("")
    Activity.AddView(MapView1, 0, 48dip, 100%x, 100%y-48dip)
    
    MapView1.SetMultiTouchEnabled(True)
    MapView1.SetZoomEnabled(True)
    
    '    initialize the MarkersBalloonOverlay and add it to the MapView
    '    no EventName is passed as we'll not listen for MarkersBalloonOverlay events in this example
    '    new with version 3.10 of the library is the *requirement* to set the default balloon overlay layout name
    '    i'm using "balloon_overlay", in this project's Objects/res/layout folder the layout file is "balloon_overlay.xml"
    MarkersBalloonOverlay1.Initialize( MapView1, "", "balloon_overlay")
    
    MapView1.AddOverlay(MarkersBalloonOverlay1)
    
    If FirstTime Then
        '    create and initialize the Markers
        
        Marker0.Initialize("", "Description but no title", 52.768, 0.194, Null)
        
        '    for Marker1 i'll use a custom icon
        Dim Icon As BitmapDrawable
        Icon.Initialize(LoadBitmap(File.DirAssets, "my_icon.png"))
        Marker1.Initialize("Home sweet home", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi egestas suscipit convallis. Etiam pellentesque gravida est, quis luctus nunc commodo at. Nam et risus orci. Integer malesuada lorem dolor. Maecenas vestibulum cursus enim, tincidunt luctus libero placerat non. In vitae metus tellus, nec euismod nibh. Phasellus ut quam vitae justo sagittis auctor. Sed vel sapien dolor. Etiam ut sem id dolor iaculis ullamcorper. Aenean eget sem nibh, a tempor augue. Nulla interdum luctus molestie.", 52.75610, 0.39748, Icon)
        '    Marker2 will display the default OSMDroid icon
        '    the default icon is used if Null is passed as the Icon parameter
        Marker2.Initialize("Elsewhere", "Downham Market", 52.60801, 0.39047, Null)
        Marker3.Initialize("Title but no description", "", 52.6959, 0.606, Null)
        
        '    Marker4 is a BalloonMarker NOT a Marker
        Marker4.Initialize("Sunny Hunstanton", "The seaside resort of Hunstanton is very popular with the tourists.", 52.9379, 0.4833, Null)
        '    a BalloonMarker has a property LayoutName which IF SET defines a balloon layout file to be used for this BalloonMarker's balloon
        '    if NOT SET then the BalloonMarker behaves the same as a Marker - it's balloon layout will be the balloon layout defined in the MarkersBalloonOverlay Initialize method
        '    in this project's Objects/res/layout folder i have created "custom_balloon_overlay.xml"
        Marker4.LayoutName="custom_balloon_overlay"
    End If
    
    '    create a List and initialize it with the 3 Markers
    Dim Markers As List
    Markers.Initialize2(Array As Object(Marker0, Marker1, Marker2, Marker3, Marker4))

    '    add the List of Markers to the MarkersBalloonOverlay
    MarkersBalloonOverlay1.AddMarkers(Markers)
    
    If FirstTime Then
        TileSource="Mapnik"
        
        '    fit the MapView to the MarkersBalloonOverlay
        MapView1.FitMapToBoundingBox(MarkersBalloonOverlay1.GetBoundingBox)
    Else
        '    restore saved zoom level and map center
        MapView1.Zoom=ZoomLevel
        MapView1.SetCenter3(MapCenter)
        If FocusedMarker<>Null Then
            '    restore the Balloon if was open before the orientation change (or Activity_Pause)
            MarkersBalloonOverlay1.FocusedMarker=FocusedMarker
        End If
    End If
    
    TileSourceSpinner.Initialize("TileSourceSelect")
    Activity.AddView(TileSourceSpinner, 0, 0, 100%x, 48dip)
    
    TileSourceSpinner.AddAll(MapView1.GetTileSources)
    TileSourceSpinner.Prompt="Select a TileSource"
    TileSourceSpinner.SelectedIndex=TileSourceSpinner.IndexOf(TileSource)
    TileSourceSelect_ItemClick(TileSourceSpinner.SelectedIndex, TileSourceSpinner.SelectedItem)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    '    save the FocusedMarker
    '    the FocusesMarker is the Marker whose Balloon is being displayed or Null if no Balloon is being displayed
    FocusedMarker=MarkersBalloonOverlay1.FocusedMarker
    MapCenter=MapView1.GetCenter
    TileSource=MapView1.GetTileSource
    ZoomLevel=MapView1.Zoom
End Sub

Sub FitMap_Click
    MapView1.FitMapToBoundingBox(MarkersBalloonOverlay1.GetBoundingBox)
End Sub

Sub TileSourceSelect_ItemClick (Position As Int, Value As Object)
    MapView1.SetTileSource(Value)
End Sub

With the previous posts circle library how would I find the closest 5 out of say 10?
And sort them closest first?

How would I tell the map to initilize 3 marker then 7 markers then 13 markers?


B4X:
....
Markers.Initialize2(Array As Object(Marker0, Marker1, Marker2, Marker3, Marker4))
....


Is there a ubound for the table array so I won't have to use the try...catch?
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi Barry.

Take a look at the attached project.
It's far from perfect but should help.

Couldn't really test the 'find nearest store' as i'm in the UK but it should work better when you are relatively close to a store.

B4X:
'Activity module
Sub Process_Globals
   Dim FocusedMarker As Marker
   Dim MyLocationEnabled As Boolean
   Dim MapCenter As GeoPoint
   Dim StoreMarkers As List
   Dim ZoomLevel As Int
End Sub

Sub Globals
   Dim MapView1 As MapView
   Dim MarkersBalloonOverlay1 As MarkersBalloonOverlay
   Dim MyLocationOverlay1 As MyLocationOverlay
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
   Activity.AddMenuItem("Find Nearest Store", "MenuHandler")
   
   MapView1.Initialize("")
   MapView1.SetMultiTouchEnabled(True)
   MapView1.SetZoomEnabled(True)
   
   MyLocationOverlay1.Initialize(MapView1, "MyLocationOverlay1")
   MapView1.AddOverlay(MyLocationOverlay1)
   
   MarkersBalloonOverlay1.Initialize(MapView1, "", "balloon_overlay")
   MapView1.AddOverlay(MarkersBalloonOverlay1)
   
   If FirstTime Then
      Dim StringUtils1 As StringUtils
      Dim StoresCSVValues As List
      StoresCSVValues=StringUtils1.LoadCSV(File.DirAssets, "coles_express_stores.csv", ", ")
      StoreMarkers.Initialize
      Dim Icon As BitmapDrawable
      Icon.Initialize(LoadBitmap(File.DirAssets, "coles_express_icon.bmp"))
      Dim Row() As String
      For i=0 To StoresCSVValues.Size-1
         Row=StoresCSVValues.Get(i)
         Dim ColesExpressStore As Marker
         ColesExpressStore.Initialize(Row(2), "", Row(1), Row(0), Icon)
         StoreMarkers.Add(ColesExpressStore)
      Next
      
      MapCenter.Initialize(-38.367172, 144.862521)
      MyLocationEnabled=MyLocationOverlay1.MyLocationEnabled
      ZoomLevel=9
   End If
   
   MarkersBalloonOverlay1.AddMarkers(StoreMarkers)
   MyLocationOverlay1.MyLocationEnabled=MyLocationEnabled
   
   If FirstTime Then
      MapView1.FitMapToBoundingBox(MarkersBalloonOverlay1.GetBoundingBox)
   Else
      MapView1.Zoom=ZoomLevel
      MapView1.SetCenter3(MapCenter)
      If FocusedMarker<>Null Then
         '   restore the Balloon if was open before the orientation change (or Activity_Pause)
         MarkersBalloonOverlay1.FocusedMarker=FocusedMarker
      End If
   End If
   
   Activity.AddView(MapView1, 0, 0, 100%x, 100%y)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   FocusedMarker=MarkersBalloonOverlay1.FocusedMarker
   MapCenter=MapView1.GetCenter
   MyLocationEnabled=MyLocationOverlay1.MyLocationEnabled
   ZoomLevel=MapView1.Zoom
End Sub

Sub MenuHandler_Click
   Dim MenuText As String
   MenuText=Sender
   Select MenuText
      Case "Find Nearest Store"
         MyLocationOverlay1.MyLocationEnabled=True
         MyLocationOverlay1.FollowLocationEnabled=True
   End Select
End Sub

Sub MyLocationOverlay1_LocationChanged(NewLocation As Location, IsFirstFix As Boolean)
   Log("MyLocationOverlay1_LocationChanged")
   If IsFirstFix<>True Then
      '   ignore the first fix, it's likely to be far less accurate then the next fix
      Dim YourLocation As GeoPoint
      YourLocation.Initialize2(NewLocation)
      Dim NearestStore As Marker
      Dim NearestStoreDistance As Float
      NearestStoreDistance=9999999999999
      Dim i As Int
      For i=0 To StoreMarkers.Size-1
         Dim StoreMarker As Marker
         StoreMarker=StoreMarkers.Get(i)
         If YourLocation.GetDistanceTo(StoreMarker.GeoPoint)<NearestStoreDistance Then
            NearestStore=StoreMarker
         End If
      Next
      Dim BoundingBox1 As BoundingBox
      BoundingBox1.Initialize2(YourLocation, NearestStore.GeoPoint)
      MapView1.FitMapToBoundingBox(BoundingBox1)
      MyLocationOverlay1.MyLocationEnabled=False
   End If
End Sub

Lots of room for improvements - you might not want to display all stores (that slows the map a bit), getting your locations then finding and displaying the nearest 10 or whatever stores would probably work better.

Martin.
 

Attachments

  • ColesExpressLocator.zip
    50.2 KB · Views: 294
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
OK, mine so far before I start looking at yours



The csv needs to be on the mnt/sdcard/download
In future the script needs a routine to download and open
the .zip from coles express web

Click Files on download and click the csv

I defaulted to my location in lat lng
you can change to match yours,
or don't start the gps to match mine
Wait for the gps to load lat, lng before pressing import csv

Click Import csv to see the points <5km away
Click Show on Map

My map tiles zip is really large so takes a bit of time to open and/or load.
I had a really small map that opens instantly.

I want to move my csv import to a menu item. etc
 

Attachments

  • ColesExpressMapMarkersBGS.zip
    298.4 KB · Views: 283
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Wow Martin.
Love your work, man!
:sign0188:

Yours looks so easy and mine at this stage looks so complex.
LOL

Thanks for the effort!
Much appreciated.
 
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
Updated to show shops <5km and a more accurate pin

I'm thinking shops < 5km would suffice instead of trying to figure out which is closest.
But may fix it n leave it just to have it there.

..
 

Attachments

  • MartinsColesExpressLocatorV2.zip
    52.6 KB · Views: 291
Last edited:
Upvote 0

BarrySumpter

Active Member
Licensed User
Longtime User
I've got it working with my gMaps.

B4X:
'Activity module
Sub Process_Globals

    Dim MapCenter As GeoPoint
    Dim TileSource As String
    Dim ZoomLevel As Int
    Dim StoreMarkers As List

    '    create some variables to save the MyLocationOverlay state
    Dim CompassEnabled, FollowLocationEnabled, MyLocationEnabled As Boolean

    '    create a new String to save the currently selected TileSource
    Dim TileSource As String

    Dim Timer1 As Timer

    Dim FocusedMarker As Marker


End Sub

Sub Globals

    Dim MapView1 As MapView
    Dim ScaleBarOverlay1 As ScaleBarOverlay
    
    '    we'll use a spinner to enable selection of TileSources
    Dim TileSourceSpinner As Spinner

    '    create the MyLocationOverlay
    Dim MyLocationOverlay1 As MyLocationOverlay

    Dim NewTileSourceName As String
    
    Dim MarkersBalloonOverlay1 As MarkersBalloonOverlay
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
  Timer1.Initialize("Timer1", 10000) ' 10000 = 10 seconds
    
    'Activity.AddMenuItem("Find Nearest Store", "MenuHandler")
    
    MapView1.Initialize("")
    MapView1.SetMultiTouchEnabled(True)
    MapView1.SetZoomEnabled(True)
    MapView1.Zoom = 19
    
    '    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)
    
    MarkersBalloonOverlay1.Initialize(MapView1, "", "balloon_overlay")
    MapView1.AddOverlay(MarkersBalloonOverlay1)
    
    If FirstTime Then
    
        'Retrieve Coles POIs from csv
    
        Dim StringUtils1 As StringUtils
        
        Dim StoresCSVValues As List
        StoresCSVValues.Initialize
        
        'retrieve Coles POIs graphics csv file
        StoresCSVValues=StringUtils1.LoadCSV(File.DirAssets, "coles_express_stores.csv", ", ")
        
        StoreMarkers.Initialize
        
        'retrieve Coles POIs graphics marker
        Dim Icon As BitmapDrawable
        Icon.Initialize(LoadBitmap(File.DirAssets, "gmap_marker_default.gif"))
        
        Dim Row() As String
        
        
'---        
        MapCenter.Initialize(-37.85, 145.06)
        ZoomLevel=17
        TileSource="Google Maps"

        'Geocoder1.Initialize
        
        Dim OfflineTileCacheFilename, TileCacheDir As String

        OfflineTileCacheFilename="GLEN_IRIS_256.zip"
        TileCacheDir=File.DirRootExternal &"/osmdroid"
        
        '    check if the offline tile cache 
        'has already been copied To the OSMDroid cache folder
        If File.Exists(TileCacheDir, OfflineTileCacheFilename)=False Then
            
            '    create the 'osmdroid' cache folder if it does not exist
            If File.Exists(TileCacheDir&"/", "")=False Then
                File.MakeDir(File.DirRootExternal, "osmdroid")
            End If
            
            '    copy the offline tile cache to the OSMDroid cache folder
            File.Copy(File.DirAssets, OfflineTileCacheFilename, TileCacheDir, OfflineTileCacheFilename)
        End If
        
        NewTileSourceName="Google Maps"
        
        Dim CurrentTilesSources As List
        CurrentTilesSources=MapView1.GetTileSources
        
        If CurrentTilesSources.IndexOf(NewTileSourceName)=-1 Then
        
        '    the NewTileSourceName has not yet been added to the MapView
            Dim MyXYTileSource As XYTileSource
            
                                     '"Google Maps"        
            MyXYTileSource.initialize(NewTileSourceName, 0, 20, 256, ".png",  "http://localhost/")
            MapView1.AddXYTileSource(MyXYTileSource)
            
            '    note that after Activity_Pause (orientation change for example) 
            ' the added XYTileSource will still exist in the MapView
            '    the added XYTileSorce will exist until the activity process is destroyed
            '    trying to add an XYTileSource more than once will not cause problems 
            ' however - the AddXYTileSource method ensures that the tile source Is only added once
        End If
        
        '    set the default initial TileSource
        TileSource=NewTileSourceName
        '        
        '        
            
        
        '----
    
        
        Dim MyLocation As Location
        MyLocation.Initialize2(-37.85, 145.06)

        Dim myLocationCircle As Circle
        myLocationCircle.Initialize(MyLocation, 5000)

        Dim Location1 As Location

        For i=0 To StoresCSVValues.Size-1
            Row=StoresCSVValues.Get(i)
            Dim ColesExpressStore As Marker

            Location1.Initialize2(Row(1), Row(0))

            If myLocationCircle.Contains(Location1) Then
                ColesExpressStore.Initialize(Row(2), "", Row(1), Row(0), Icon)
                StoreMarkers.Add(ColesExpressStore)
            End If
        Next
        
'        MyLocationOverlay1.CompassEnabled=True
'        MyLocationOverlay1.MyLocationEnabled=True
'        MyLocationOverlay1.FollowLocationEnabled=True
'        
'        MyLocationEnabled=MyLocationOverlay1.MyLocationEnabled
    
    End If
    
        MapView1.Zoom=ZoomLevel
        MapView1.SetCenter3(MapCenter)


    '-----
    ScaleBarOverlay1.Initialize(MapView1)
    MarkersBalloonOverlay1.AddMarkers(StoreMarkers)
    MyLocationOverlay1.MyLocationEnabled=MyLocationEnabled
    
    TileSourceSpinner.Initialize("TileSourceSelect")
    Activity.AddView(TileSourceSpinner, 0, 0, 100%x, 48dip)
    
    TileSourceSpinner.AddAll(MapView1.GetTileSources)
    TileSourceSpinner.Prompt="Select a TileSource"
    TileSourceSpinner.SelectedIndex=TileSourceSpinner.IndexOf(TileSource)
    TileSourceSelect_ItemClick(TileSourceSpinner.SelectedIndex, TileSourceSpinner.SelectedItem)


    If FirstTime Then
        MapView1.FitMapToBoundingBox(MarkersBalloonOverlay1.GetBoundingBox)
    Else
        If FocusedMarker<>Null Then
            '    restore the Balloon if was open before the orientation change (or Activity_Pause)
            MarkersBalloonOverlay1.FocusedMarker=FocusedMarker
        End If
    End If
    
    'Activity.AddView(MapView1, 0, 48dip, 100%x, 100%y - 48dip)
    Activity.AddView(MapView1, 0, 0, 100%x, 100%y)
    
    MyLocationOverlay1.MyLocationEnabled=True
    MyLocationOverlay1.FollowLocationEnabled=True

    
    
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)


    MapCenter=MapView1.GetCenter

    '    save the currently selected MapView TileSource
    TileSource=MapView1.GetTileSource
    ZoomLevel=MapView1.Zoom


    FocusedMarker=MarkersBalloonOverlay1.FocusedMarker
    MyLocationEnabled=MyLocationOverlay1.MyLocationEnabled
    
        '    disable MyLocationOverlay compass and GPS listening
    MyLocationOverlay1.CompassEnabled=False
    MyLocationOverlay1.MyLocationEnabled=False

    
End Sub


Sub TileSourceSelect_ItemClick (Position As Int, Value As Object)
    MapView1.SetTileSource(Value)
    
End Sub
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)
    
    MyLocationOverlay1.CompassEnabled=True
    MyLocationOverlay1.MyLocationEnabled=True
    MyLocationOverlay1.FollowLocationEnabled=True

    
    Timer1.Enabled = True
    
End Sub
Sub Timer1_Tick

     'Handle tick events
    MyLocationOverlay1.CompassEnabled=True
    MyLocationOverlay1.MyLocationEnabled=True
    MyLocationOverlay1.FollowLocationEnabled=True
        
    Timer1.Enabled = False
    
End Sub
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi Barry.

Your code needed some things changed - the Spinner was only added if FirstTime was True.
In the Spinner ItemClick you were not saving the newly selected TileSource.

Then i had to add a test offline map archive to make sure that code all worked - the code works fine but my test offline map archive contained just a few tiles for zoom level 0 to 14 so when the app displays the nearest stores there are no tiles.

Anyway - your code works well, only displaying stores within a 5km radius keeps the map performance acceptable.

Look at the attached screengrab, i used my ImageButtonsView to add some buttons to the MapView then AHQuickAction3D to show a list of tile sources - you can see i didn't add all possible tile sources.
Works well and takes up far less space than a Spinner, and you add as many buttons as you require - the ImageButtonsView will scroll if the buttons are too wide to display all at the same time.
So a button to enable MyLocation, a button to center the map on all visible stores etc would make your app a bit more useable...

I've attached your updated code , you'll have to revert some changes where i've used my own offline tile archive.

While we're on the subject of offline maps you might like to take a look at an Android library i'm hoping to create a B4A library from...

mapsforge can render what's known as vector data.
Map tiles are raster data, vector data is non-visual data from which visual tiles can be rendered.
Now that more and more Android devices contain powerful CPUs it is possible for an Android device to convert vector data (on the device) to visual tiles on the fly.

If you have time you could download the mapsforge demo app and then download the vector data for the area you wish to view and see it in action!
Vector data can be downloaded from HERE, you can see that the vector data for Australia/Oceania is just 233MBs.

In the demo app click the Menu button and look at the Preferences.
See Font size?
Because we're dealing with vector data and you device renders tiles from the vector data on the fly, you can change the font size of the placenames on the map.
You can also define custom rendering themes - change the color of highways, define which zooms levels to display any feature and much much more, take a look here.

mapsforge will be a tricky B4A library to create but i hope to succeed, no idea when though as i am busy with work at the moment...

Martin.
 

Attachments

  • ColesExpressLocator - Martin_updated.zip
    53.5 KB · Views: 355
  • map_type_select.jpg
    map_type_select.jpg
    59.1 KB · Views: 422
Upvote 0
Top