OSM Droid Map Issue

marcel

Active Member
Licensed User
Longtime User
Hi,

I have the following issue. When I display a point on the map and go to this location it does not work. When I use the debugger it works well? I suppose that it has to do with timing or I am doing something not correct below my code of the test activity.

The problem is when the SingleMap is true and display one point.

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 SingleMap As Boolean
   Dim selectedItem As JD
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 bar As BarView
    Dim mp As MapView
   Dim MarkersOverlay1 As MarkersOverlay
   Dim MapIcon As BitmapDrawable
     Dim Markers As List
   Dim MarkersFocusOverlay1 As MarkersFocusOverlay
   Dim MinimapOverlay1 As MinimapOverlay
   Dim ovlLocation As MyLocationOverlay
End Sub

Sub Activity_Create(FirstTime As Boolean)
    MapIcon.Initialize(LoadBitmap(File.DirAssets, "map-pin.png"))

   bar.Initialize(Me,"Main")
   bar.headerVisible=False
   bar.AddToActivity(Activity,0,0dip,100%x,100%y)

     mp.Initialize("")
   Activity.AddView(mp,0,0,100%x,100%y-bar.btnBarHeight)
     mp.SetMultiTouchEnabled(True)
     MarkersOverlay1.Initialize(mp, "MarkersOverlay1")
     mp.AddOverlay(MarkersOverlay1)

     '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
     ovlLocation.Initialize(mp,"mylocation")
     mp.AddOverlay(ovlLocation)
  
     '   ensure that the MinimapOverlay is the LAST overlay added to the MapView
     MinimapOverlay1.Initialize(mp)
    mp.AddOverlay(MinimapOverlay1)


   If SingleMap Then
        DisplayPoint
   Else
        mp.Zoom=10
        mp.SetCenter(Update.loc.latitude,Update.loc.Longitude)
        mp.AnimateTo2(Update.loc)
        DisplayPoints   
   End If
  
End Sub

Sub DisplayPoints
  If Not (Markers.IsInitialized) Then Markers.Initialize
  Markers.Clear
  MarkersOverlay1.RemoveMarkers
  For Each e In Main.items
        Dim item As JD = e
        Dim m As Marker
      m.Initialize(item.GetTitle, item.GetCompany,item.GetLatitude,item.GetLongitude,MapIcon)
      Markers.Add(m)
  Next
  MarkersOverlay1.AddMarkers(Markers)
  'mp.FitMapToBoundingBox(MarkersOverlay1.GetBoundingBox)
End Sub

Sub DisplayPoint
  If Not (Markers.IsInitialized) Then Markers.Initialize
  Markers.Clear
  MarkersOverlay1.RemoveMarkers
  Dim m As Marker
  m.Initialize(selectedItem.GetTitle, selectedItem.GetCompany,selectedItem.GetLatitude,selectedItem.GetLongitude,MapIcon)
  Markers.Add(m)
  MarkersOverlay1.AddMarkers(Markers)
  mp.AnimateTo(selectedItem.GetLatitude,selectedItem.GetLongitude)
  mp.Zoom=16
End Sub
 
Last edited:

warwound

Expert
Licensed User
Longtime User
What do you mean by 'it does not work'?

Do you only see downloaded map tiles if the debugger is enabled?
If so then your app sounds like it's missing the required permission to access the internet.
(Enabling the debugger adds the internet permission to your app).

The OSMDroid library should automatically add the permissions that it requires - have you edited the manifest and prevented OSMDroid from adding the permission?

Martin.
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User
What do you mean by 'it does not work'?

It had some wierd behaviour but I know figured out that it was just slow. I need to have more pacient

Another thing was that when I call the sub displaypoint the map didn't go to the location using the AnimateTo function. But when I swapped the zoom and the AnimateTo function it worked....
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…