Android Question OSMdroid geopoint.lat and geopoint.lon

davelew1s

Active Member
Licensed User
Longtime User
Hello!
I'm using OSMdroid 4.1 and am having problems using geopoint.latitude and geopoint.longitude this is part of the code:-
code:
gp.Latitude = cell(1)
Log(cell(1) & " " & gp)

gp.Longitude = cell(2)
Log(cell(2) & " " & gp)
cell(1) contains lat in decimal
cell(2) contains lon in decimal
but gp doesn't contain the correct lat and lon
Any help?
 
Last edited:

davelew1s

Active Member
Licensed User
Longtime User
Thanks for the reply here is what I think is the relevant code:-

B4X:
If follow = True Then              
               'Dim gp As OSMDroid_GeoPoint
               'gp.Initialize(cell(1),cell(2))
                            
               gp.Latitude = cell(1)
               Log(cell(1) & "  " & gp)
              
               gp.Longitude =   cell(2)
               Log(cell(2) & "  " & gp)
                        
               MapView1.GetController.SetCenter(gp )
               track.AddPoint (gp)
               lblTest5 .Text = track.GetNumberOfPoints
               MapView1.GetOverlays.Add  (track )  
              
             End If

I originally used the 2 commented lines without the next 4 and it worked ok but after 100 + points the display became very unresponsive
so I moved the Dim gp to globals and gp.initialze to Activity_Create(FirstTime As Boolean) hopng it would help...but cannot get the gp.lat & gp.lon to
work. Here is the Log:-

50.8996 (GeoPoint) 50899600,-4960900,0
-4.9609 (GeoPoint) -4960900,-4960900,0
cell(1) contained 50.8996
cell(2) contained -4.9609
as far as I can see only the latitude changes.
Hope this is enough info .

Dave.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
If it works when you Dim new GeoPoint objects for each part of the track then that is what you must do.
The track will (internally) contain a GeoPoint for each point in the track, you can't reuse the last GeoPoint for the next GeoPoint as you are finding out.

Revert to your orginal code - Dimming a new GeoPoint for each new point to add to the track - and then tackle what seems to be memory issues when the track contains many points.
 
Upvote 0

davelew1s

Active Member
Licensed User
Longtime User
Thanks warwound .... that's what i've done but i still have the problem of the track containing many points. I have done a test using
OSMdroid_3_0_8 i can add over 1000 without any real problems but with OSMdroid_4_1 at 300 it's almost unusable.
Any thoughts? Dave.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Thanks warwound .... that's what i've done but i still have the problem of the track containing many points. I have done a test using
OSMdroid_3_0_8 i can add over 1000 without any real problems but with OSMdroid_4_1 at 300 it's almost unusable.
Any thoughts? Dave.

I've just looked at the PathOverlay source code and there's not much difference between version 3.0.8 and 4.1.
But the even newer 4.2 PathOverlay source code has a comment:
@deprecated This class is no longer maintained and has various issues. Instead you should use the Polyline class in OSMBonusPack.
A little more info here: https://github.com/osmdroid/osmdroid/issues/40.

I'll have a look at the OSMBonusPack Polyline class now and see if it can be quickly wrapped for use with OSMDroid version 4.1.

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Well quickly wrapping the OSMDroid Polyline class isn't possible.
The latest version of OSMBonusPack works with the latest version of OSMDroid (4.2).

To use the latest OSMBonusPack would require that i also wrap version 4.2 of OSMDroid.
I'm too busy with work to wrap the latest OSMDroid and then OSMBonusPack.

Martin.
 
Upvote 0

davelew1s

Active Member
Licensed User
Longtime User
Hi Martin!
Thanks for looking at the problem, i appreciate you taking the time.
Now i know it's not me i will try to find a workround, probabaly using less points, this of course
spoils a curve but it's better than no point at all.
Thanks again for your help. Dave.
 
Upvote 0

davelew1s

Active Member
Licensed User
Longtime User
SOLVED!
I was just about to give up on this app when i found a solution. Below it just 1 SUB that plots points i moved the line
'MapView1.GetOverlays.Add (track )' from position 1 to 2 and this solved it, i can now plot as many as i like without any slowing down.
I also found that this line only needs to be executed oly once and allows all other SUBs that plot points to work ok. So i moved it into
'Sub Activity_Create(FirstTime As Boolean)' and this also works.

B4X:
Sub getTrail
    Dim temp(3) As String 
     Dim ii As Int = 0
For i = trail.Size - 4 To 0 Step - 1
        temp(ii) = trail.get (i)
        ii = ii + 1
    If ii = 3 Then
        ii = 0       
        track  .AddPoint2(temp(2),temp(1))       
        'MapView1.GetOverlays.Add  (track )            position 1
        lblTest5 .Text = track.GetNumberOfPoints
    End If
Next
'Log("Get trail")
'MapView1.GetOverlays.Add  (track )                    position 2
MapView1.Invalidate
End Sub

I also found that Rapid debug now works faster before it was so slow that it was almost unuseable.
So 1 line moved has solved 2 problems ... not sure why probably clogging up memory.
I don't know if this is the correct way to solve it but it works for me.
Dave.
 
Upvote 0
Top