Giter VIP home page Giter VIP logo

geometry-library's Issues

PHP 7.4 Depreciated Syntax

Since php7.4 syntax with curly braces is deprecated, this seems to affect lines 304 & 313 of PolyUtil.php - Possible other files are affected to, personally I am only using PolyUtil..

Errors with isLocationOnPath

Hi,

if I calculate distance from a point and a segment:

$response =  $polyUtil->distanceToLine(
	['lat' => 46.111691, 'lng' => 13.003583], // point array [lat, lng]
	['lat' => 46.112111, 'lng' => 13.003857], // line startpoint array [lat, lng]
	['lat' => 46.112113, 'lng' => 13.003888] // line endpoint array [lat, lng]
   );

I'll obtain 51.256 meters (it'is about the correct distance in real world).
But if i calculate intesection:

$response = $polyUtil->isLocationOnPath(
	['lat' => 46.111691, 'lng' => 13.003583], // point array [lat, lng]
	[ // poligon arrays of [lat, lng]
	  ['lat' => 46.112111, 'lng' => 13.003857], 
	  ['lat' => 46.112113, 'lng' => 13.003888]
	],
	10 // 10 meters of tollerance
);

I'll obtain true with only 10 meters of tollerance.

I've other examples of wrong intersections.

Update

Could you update the version on packagist to 1.0.2 as well as the alexpechkarev/google-maps depedency? This is popping up in our composer outdated Thanks! :-)

Issue with PolyUtil::distanceToLine function

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

isLocationOnPath issue,

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 ?

Uninitialized string offset

When using isLocationOnEdge on several decoded polylines, I am getting error on some encoded polylines: Uninitialized string offset: 156 in PolyUtil.php on line 313, which points to a decoding function. I have escaped all the backslashes from encoded polyline at the time of creating in Javascript, but I am not aware if some characters should be escaped also in PHP.

Encoded polyline, which produces the error is:
polyline_error.txt

How do I include into a php file?

I have used the following code to add the SphericalUtil into the php file but giving this error: Class 'SphericalUtil' not found. Hopefully someone can help.

Do I need to use composer? Is it possible not to?

 include('geometry-library/SphericalUtil.php');
        $HexLib= new SphericalUtil();

tolerance in meters or degrees

documenation showing tolerance in meters in example as degrees. i think meters or correct its working. and isLocationOnEdge returns 1 on true nothing on false

Perpendicular of a line in PHP

Good day friend.
How can I make a perpendicular of a line in PHP?
In JAVASCRIPT (gmaps)

`

var spherical = google.maps.geometry.spherical;

var F = new google.maps.LatLng(51.524, -0.099); 
var T = new google.maps.LatLng(51.531, -0.114); 

var myOptions = {
    zoom: 14,
    center: F,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

// Draw line
var segmentCoordinates = [F, T ];
var segment = new google.maps.Polyline({
    path: segmentCoordinates,
    geodesic: true,
    strokeColor: '#00FF00',
    strokeOpacity: 1.0,
    strokeWeight: 2,
    map: map
  });    

// Get direction of the segment
var heading = spherical.computeHeading(F, T);

var dist = 500; // distance in meters    
var A = spherical.computeOffset(F, dist, heading+90);
var B = spherical.computeOffset(F, dist, heading-90);
var perpendicularCoordinates = [A, B ];

var perpendicular = new google.maps.Polyline({
    path: perpendicularCoordinates,
    geodesic: true,
    strokeColor: '#FF0000',
    strokeOpacity: 1.0,
    strokeWeight: 2,
    map: map
  });    

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.