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

Problem with calculating distance using Vincenty #107

Open
bjoernffm opened this issue Jun 30, 2024 · 1 comment
Open

Problem with calculating distance using Vincenty #107

bjoernffm opened this issue Jun 30, 2024 · 1 comment

Comments

@bjoernffm
Copy link

Hi there,

I try to calculate the distance between two points using this code:

$coordinate1 = new Coordinate(-5.59248, -78.774002);
$coordinate2 = new Coordinate(5.79, 101.15);

$distance = $coordinate1->getDistance($coordinate2, new Vincenty());

It throws an NotConvergingException and I don't understand why.

Is there any solution to this problem or is the vincenty method limited regarding any circumstances?

Thank you!

mjaschen added a commit that referenced this issue Jul 1, 2024
mjaschen added a commit that referenced this issue Jul 1, 2024
@mjaschen
Copy link
Owner

mjaschen commented Jul 1, 2024

Hello,

as described here, the Vincenty formular can fail to converge in some cases:

Vincenty’s inverse solution can fail on nearly antipodal points. Testing with Geographic­Lib test data, I’ve found this can happen with distances greater than 19,936 km, or within around 75 km of the antipodal point.

I've added a test case and will update the documentation.

As a workaround you can wrap the getDistance() method call in try {} catch {} and recalculate with Haversine in the case that Vincenty fails.

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

No branches or pull requests

2 participants