alexpechkarev / geometry-library

PHP Geometry Library provides utility functions for the computation of geometric data on the surface of the Earth. Code ported from Google Maps Android API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

isLocationOnPath issue,

azureshin opened this issue · comments

PHP VERSION

$lat = 25.771932423027444;
$lng = -80.1869744682312;

$content = [['lat' => 25.774, 'lng' => -80.190],['lat' => 18.466, 'lng' => -66.118],['lat' => 32.321, 'lng' => -64.757]];
   
$response =  \GeometryLibrary\PolyUtil::isLocationOnPath(['lat' => $lat, 'lng' => $lng],$content,0.001);
//0.001 = 110M

echo $response; 
//resule : print false

JAVASCIPT VERSION
https://www.lucien.mobi/pointline.html

please click marker, infowindow show "NEAR" (TRUE).

php code and JS code alike

How can I fix PHP VERSION ?

Hi @azureshin,

Please can you try to reduce $tolerance from 0.001 to 0.1 ?
According to Floating point precision "numbers have limited precision and non elementary arithmetic operations may give larger errors, and, of course, error propagation must be considered when several operations are compounded."

Looking deeper in the code:
// $toleranceEarth = 0.001;
$tolerance = $toleranceEarth / MathUtil::EARTH_RADIUS; // 6371009
// tolerance at this stage 1.5696100884491E-10
// than following is called
$havTolerance = MathUtil::hav($tolerance);
//$havTolerance = 6.159189574403E-21

Dear @alexpechkarev

I try to $tolerance from 0.001 to 0.1
but it return false

thanks....

Hi @azureshin,

Have run your example, following will work, please note tolerance is given in meters, in this case 130m will return true.

The location ['lat' => 25.771, 'lng' => -80.186] is considered on path with tolerance 130 meters, return true.
tolerance = 140 - return true
tolerance = 130 - return true
tolerance = 120 - return false
tolerance = 100 - return false
and so on

      $r = \GeometryLibrary\PolyUtil::isLocationOnPath(
              ['lat' => 25.771, 'lng' => -80.186], // point array [lat, lng]
              [ // poligon arrays of [lat, lng]
                ['lat' => 25.774, 'lng' => -80.190], 
                ['lat' => 18.466, 'lng' => -66.118], 
                ['lat' => 32.321, 'lng' => -64.757]
              ],
                130);