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

Issue with PolyUtil::distanceToLine function #11

Closed
gistrec opened this issue Feb 9, 2020 · 0 comments
Closed

Issue with PolyUtil::distanceToLine function #11

gistrec opened this issue Feb 9, 2020 · 0 comments

Comments

@gistrec
Copy link
Contributor

gistrec commented Feb 9, 2020

Hi, i found the following test for PolyUtil::distanceToLine function in googlemaps/android-maps-utils library:

LatLng startLine = new LatLng(28.05359, -82.41632);
LatLng endLine = new LatLng(28.05310, -82.41634);
LatLng p = new LatLng(28.05342, -82.41594);

double distance = PolyUtil.distanceToLine(p, startLine, endLine);
assertEquals(37.947946, distance, 1e-6);

But for this data PolyUtil::isLocationOnEdge function returns incorrect value 42.989894449231
Code for test:

<?php

require_once("./MathUtil.php");
require_once("./SphericalUtil.php");
require_once("./PolyUtil.php");

$point = ['lat' => 28.05342, 'lng' =>  -82.41594];

$start = ['lat' => 28.05359, 'lng' => -82.41632];
$end   = ['lat' => 28.05310, 'lng' => -82.41634];

$response =  \GeometryLibrary\PolyUtil::distanceToLine($point, $start, $end);

var_dump($response);

I think this is due to difference in source code between you're library and googlemaps/android-maps-utils library:

+$sa = array('lat' => $p['lat'] - $start['lat'], 'lng' => $p['lng'] - $start['lng']);
+$sb = array('lat' => ($u * ($end['lat'] - $start['lat'])), 'lng' => ($u * ($end['lng'] - $start['lng'])));
+return SphericalUtil::computeDistanceBetween($sa, $sb);
-LatLng su = new LatLng(start.latitude + u * (end.latitude - start.latitude), start.longitude + u * (end.longitude - start.longitude));
-return computeDistanceBetween(p, su);

I will create PR to fix this issue

alexpechkarev added a commit that referenced this issue Feb 10, 2020
Fix PolyUtil distanceToLine function. Close #11
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

1 participant