TurfJS Snap to the second closest

478 Views Asked by At

I'm using the TurfJS library in one of my projects to determine the distance to the destination using a defined route as my base, but because of GPS drift, I have a situation where the point snaps to the "other"side of the road/route.

Is there a way to get the second closest line element back, which in theory should be the line going back to the destination?

Any suggestions would be great...!

PS - the image is a representation where the roue is actually coming back on the same road.

enter image description here

1

There are 1 best solutions below

4
Michael Entin On

First, an observation: the second line segment might be on the same "wrong" part of the line as the first one.

What I would use is lineSlice function. Once you know vehicle passed particular point, slice the line and get the remaining part. Then find the closest point using this remaining part only.