Pieter Coetzer
Pieter Coetzer

Reputation: 75

TurfJS Snap to the second closest

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

Upvotes: 0

Views: 615

Answers (1)

Michael Entin
Michael Entin

Reputation: 7744

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.

Upvotes: 0

Related Questions