Android Question calc GPS point between to GPS points

me68

Member
Licensed User
Longtime User
Hello!

I'm working on a navigation app using Google Directions.

After decoding json result i decode polyline points and store them in lMapsPoints list.

So i'm, able to draw the route to maps and do maneuver infos when i'm nearby an maneuver point.

Now i want to use these polyline points to check if i'm off the route (f.e. distance < 10 meters). If i'm off the route i do a new google directions request so the idea.

But if there is a long line between two polyline points f.e. on a highway, i'm off the route on checking the next polyline point.

So i will fill up the list with points. But i do not know how to calc a new gps point which should be in the middle of two other gps points.

My MapsVerifyPoints sub looks like following:

B4X:
For j = 0 To (lMapsPoints.Size - 1) / 2 Step 2
    mpiPoint1 = lMapsPoints.Get(j)
    mpiPoint2 = lMapsPoints.Get(j + 1)
    lPoint1.Latitude = mpiPoint1.dLatitude
    lPoint1.Longitude = mpiPoint1.dLongitude
    lPoint2.Latitude = mpiPoint2.dLatitude
    lPoint2.Longitude = mpiPoint2.dLongitude
   
    fDistance = lPoint1.DistanceTo(lPoint2) ' meters
    If fDistance > 10 Then ' distance to big for "route off" calc
      iNumberPoints = iNumberPoints + 1
      Log("Points " & j & " " & (j + 1) & ": Distance=" & NumberFormat2(fDistance,0,0,0,False))
     
      'lMapsPoints.InsertAt ???
    End If
  Next
  Log("NumberPoints=" & iNumberPoints & "/" & lMapsPoints.Size)


Is there already any function available for calculating this?


Martin
 

me68

Member
Licensed User
Longtime User
Hello Erel!

Yes exactly. I'll refine the polyline points to set one point in the middle of two other points.


Martin
 
Upvote 0

me68

Member
Licensed User
Longtime User
Yes.

One example of a route about 20km

B4X:
MapsVerifyPoints

Points 0 1: Distance=11
Points 10 11: Distance=12
Points 12 13: Distance=19
Points 14 15: Distance=16
Points 16 17: Distance=10
Points 22 23: Distance=80
Points 24 25: Distance=50
Points 26 27: Distance=64
Points 30 31: Distance=63
Points 32 33: Distance=55
Points 34 35: Distance=52
Points 36 37: Distance=76
Points 38 39: Distance=53
Points 40 41: Distance=54
Points 42 43: Distance=83
Points 44 45: Distance=28
Points 46 47: Distance=50
Points 50 51: Distance=26
Points 52 53: Distance=65
Points 54 55: Distance=47
Points 56 57: Distance=47
Points 58 59: Distance=70
Points 60 61: Distance=83
Points 62 63: Distance=50
Points 64 65: Distance=51
Points 66 67: Distance=234
Points 68 69: Distance=185
Points 72 73: Distance=88
Points 74 75: Distance=59
Points 76 77: Distance=36
Points 78 79: Distance=45
Points 80 81: Distance=67
Points 82 83: Distance=14
Points 84 85: Distance=18
Points 86 87: Distance=68
Points 92 93: Distance=36
Points 94 95: Distance=28
Points 96 97: Distance=21
Points 98 99: Distance=29
Points 100 101: Distance=24
Points 102 103: Distance=12
Points 106 107: Distance=23
Points 108 109: Distance=12
Points 110 111: Distance=12
Points 112 113: Distance=23
Points 114 115: Distance=12
Points 120 121: Distance=22
Points 122 123: Distance=18
Points 124 125: Distance=43
Points 126 127: Distance=21
Points 128 129: Distance=30
Points 130 131: Distance=25
Points 132 133: Distance=22
Points 134 135: Distance=36
Points 136 137: Distance=21
Points 138 139: Distance=16
Points 142 143: Distance=65
Points 144 145: Distance=61
Points 148 149: Distance=30
Points 150 151: Distance=23
Points 152 153: Distance=26
Points 154 155: Distance=44
Points 156 157: Distance=54
Points 158 159: Distance=89
Points 160 161: Distance=54
Points 162 163: Distance=41
Points 164 165: Distance=32
Points 166 167: Distance=31
Points 168 169: Distance=20
Points 170 171: Distance=36
Points 172 173: Distance=32
Points 174 175: Distance=16
Points 176 177: Distance=38
Points 178 179: Distance=36
Points 180 181: Distance=43
Points 182 183: Distance=24
Points 186 187: Distance=30
Points 188 189: Distance=30
Points 190 191: Distance=87
Points 192 193: Distance=62
Points 194 195: Distance=10
Points 198 199: Distance=351
Points 200 201: Distance=95
Points 204 205: Distance=25
Points 206 207: Distance=61
Points 208 209: Distance=24
Points 210 211: Distance=40
Points 212 213: Distance=18
Points 214 215: Distance=56
Points 216 217: Distance=38
Points 222 223: Distance=41
Points 224 225: Distance=65
Points 226 227: Distance=54
Points 228 229: Distance=75
Points 230 231: Distance=45
Points 232 233: Distance=97
Points 234 235: Distance=51
Points 236 237: Distance=39
Points 238 239: Distance=46
Points 240 241: Distance=38
Points 242 243: Distance=87
Points 244 245: Distance=12
Points 246 247: Distance=19
Points 248 249: Distance=25
Points 250 251: Distance=35
Points 252 253: Distance=20
Points 254 255: Distance=26
Points 256 257: Distance=25
Points 258 259: Distance=11
Points 260 261: Distance=15
Points 262 263: Distance=17
Points 264 265: Distance=32
Points 266 267: Distance=43
Points 286 287: Distance=65
Points 288 289: Distance=101
Points 290 291: Distance=35
Points 292 293: Distance=27
Points 294 295: Distance=14
Points 296 297: Distance=42
Points 298 299: Distance=37
Points 300 301: Distance=56
Points 302 303: Distance=50
Points 304 305: Distance=145
Points 306 307: Distance=41
Points 308 309: Distance=90
Points 310 311: Distance=26
Points 312 313: Distance=56
Points 314 315: Distance=46
Points 316 317: Distance=21
NumberPoints=129/634

The longest line ist 351m. So if i go through the list for checking if i'm on the route with distanceto i get a "off route" in this case, on chekcing my "10 meter discrepancy".

Stupid idea?

Martin
 
Upvote 0

me68

Member
Licensed User
Longtime User
Hello Erel!

I do following:

I use GPS data from the android device for origin.
I use GPS data form my POIs for destination.

I make a http-Request with f.e.

http://maps.googleapis.com/maps/api...1,16.324900053441525&sensor=false&language=de

I decode the http-Response using json library. Then i especially decode polyline/points and store them in the list. Then i use gmap.AddPolyline to draw the routing line with this list. So i have the route on the map.

If i follow the route all is ok. But if a leave the route i have to do a new google directions http request with the current gps data. So i need a "on the route?" check.

maps.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I see. I recommend you to follow these steps:
1. Convert all the coordinates to UTM coordinates (see Geodesic class). It is easier to work with UTM coordinates.
2. Calculate the lines equations between each two corresponding points.

Now when you find your current location you should calculate the distance between the current point and each of the lines.
 
Upvote 0

me68

Member
Licensed User
Longtime User
Hello Erel!

Please have a look to the data - i see no easy calc in UTM coordinates.

B4X:
MapsVerifyPoints

mpiPoint1.dLatitude=47.53858, mpiPoint1.dLongitude=16.43246
mpiPoint2.dLatitude=47.53866, mpiPoint2.dLongitude=16.43255
uPoint1.X=607803.4396406484, uPoint1.Y=5266011.649603361
uPoint2.X=607810.0486715373, uPoint2.Y=5266020.665263658
Points 0 1: Distance=11
mpiPoint1.dLatitude=47.5387, mpiPoint1.dLongitude=16.4312
mpiPoint2.dLatitude=47.53873, mpiPoint2.dLongitude=16.43104
uPoint1.X=607708.3710309517, uPoint1.Y=5266023.237142716
uPoint2.X=607696.2686222856, uPoint2.Y=5266026.349233777
Points 10 11: Distance=12
mpiPoint1.dLatitude=47.53875, mpiPoint1.dLongitude=16.43084
mpiPoint2.dLatitude=47.53878, mpiPoint2.dLongitude=16.43059
uPoint1.X=607681.1764686117, uPoint1.Y=5266028.294540267
uPoint2.X=607662.3010548127, uPoint2.Y=5266031.281897217
Points 12 13: Distance=19
mpiPoint1.dLatitude=47.53883, mpiPoint1.dLongitude=16.43019
mpiPoint2.dLatitude=47.53885, mpiPoint2.dLongitude=16.42998
uPoint1.X=607632.09634306, uPoint1.Y=5266036.28406224
uPoint2.X=607616.2516837004, uPoint2.Y=5266038.215674486
Points 14 15: Distance=16

Could you please push me in the right direction?


Martin
 
Upvote 0

me68

Member
Licensed User
Longtime User
I have already a function do caculate distance between two points - it's working perfect.

My problem is checking if i'm on the computed route or not. So my idea was to use the points of polyline i already have to draw the route.

So i check my current gps position against the points of polyline (i will mark one point as passed, if the distance is lower then f.e. 5 meters). Then i check the next point of polyline against my current gps position. So i can say: "on route"/"off route". If "off route" i have to recalculate the route.

Google opimized this points of polyline and so there are as less as possible points available. The distance from one point to the next for drawing this polyline, is even short. But if there is a longer distance i have a leak and will produce a "off route" with my simple calc "if my distance is more then 5 meters from the next point of polyline").

So i will fill up this points so all points has a distance max. i'll use as value for aberration.


Martin
 
Upvote 0

jamesnz

Active Member
Licensed User
Longtime User
How did you get on with this ? I'm trying to build a mapquest navigator
without complicating things too much I was wondering about working out just the required heading to the next point and then using the compass to check that I was roughly heading in the right direction ( say within 90 degrees ) of course not all roads go straight to the next point but I notice googles polylines are usually on the apex of corners, could also use the accelerometer to see if there had been any sharp turns etc
 
Upvote 0
Top