Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.5.0 to 1.2.0 versions are not giving me right values for LineString.closestCoordinate(to:) function #142

Open
vishnu-devineni opened this issue Apr 5, 2021 · 1 comment

Comments

@vishnu-devineni
Copy link

vishnu-devineni commented Apr 5, 2021

0.5.0 to 1.2.0 versions are not giving me right values for LineString.closestCoordinate(to:) function.

My project's current version is 0.3.0 and was able to calculate re-route when the distance between the current location and the current step's polyline is more than 100 or 200 meters.
I have upgraded to 1.2.0 and I am not able to request for rerouting since closestCoordinate function is not returning proper value. Even 0.5.0 also not returning me proper values (IndexedCoordinate).
But I am able to get proper values if I use 0.4.0 version.

Previously I were using Polyline(coordinates) to create a polyline, But after upgrading to 0.4.0 or higher version, I have used LineString(coordinates) to create the polyline which can be used to get the closestCoordinate (IndexedCoordinate). This IndexedCoordinate always showing a distance of either 46.7*** or -1.*** even though I had travelled for more than 50km.

github "mapbox/turf-swift" ~> 1.2
github "mapbox/turf-swift" == 1.2.0

I have added the library using the above two ways in my cartfile.

Please guide me to resolve my issue.

@Juju31Fr
Copy link

Juju31Fr commented Dec 3, 2021

I have the same issue, and I'm surprised nobody has answered this point ...
In turf.js, nearestPointOnLine returns 4 elements:

  • closest point on the line to point
  • index : closest point was found on nth line part
  • dist : distance between pt and the closest point
  • location : distance along the line between start and the closest point.

In previous releases, turf-swift was returning 3 elements:

  • closest point on the line to point (CLLocationCoordinate2D)
  • index : closest point was found on nth line part (Int)
  • dist : distance between pt and the closest point (CLLocationDistance)

In the latest release, it is returned 3 elements as well, but the distance is no more the same data. It was the distance between pt and the closest point, it is now distance along the line between start and the closest point.

From my point of view, the 4 elements are important, and you should add a property to IndexedCoordinate to return a piece of information aligned with turf.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants