Sh3ll
OdayForums


Server : Apache
System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64
User : tradze ( 1001)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/tradze/public_html/dev-test/vendor/alexpechkarev/google-maps/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/tradze/public_html/dev-test/vendor/alexpechkarev/google-maps/src/Directions.php
<?php namespace GoogleMaps;

use GeometryLibrary\PolyUtil;
use Illuminate\Support\Arr;

/**
 * Description of GoogleMaps
 *
 * @author Alexander Pechkarev <alexpechkarev@gmail.com>
 */
class Directions extends WebService{
    /**
     * Get Web Service Response
     *
     * @param string|false $needle
     * @return string
     * @throws \ErrorException
     */
    public function get( $needle = false ){

        if( $this->service['decodePolyline'] ){
            $this->setEndpoint('json');

            return $this->decode( parent::get( $needle ));
        }

        return parent::get( $needle );
    }
    /***/

    /**
     * To determine whether a point falls on or near a polyline, or on or near
     * the edge of a polygon, pass the point, the polyline/polygon, and
     * optionally a tolerance value in degrees
     * https://developers.google.com/maps/documentation/javascript/geometry#isLocationOnEdge
     *
     * @param double $lat
     * @param double $lng
     * @param double $tolerance
     * @return boolean
     * @throws \ErrorException
     */
    public function isLocationOnEdge( $lat, $lng, $tolerance = 0.1){

        $point = [
            'lat' => $lat,
            'lng' => $lng
        ];

        $polygon = Arr::get( json_decode( $this->get(), true ), 'routes.0.overview_polyline.points') ;

        return PolyUtil::isLocationOnEdge($point, $polygon, $tolerance);
    }

    /**
     * To find whether a given point falls within a polygon
     * https://developers.google.com/maps/documentation/javascript/geometry#containsLocation
     *
     * @param double $lat
     * @param double $lng
     * @return boolean
     * @throws \ErrorException
     */
    public function containsLocation($lat, $lng){

        $point = [
            'lat' => $lat,
            'lng' => $lng
        ];

        $polygon = Arr::get( json_decode( $this->get(), true ), 'routes.0.overview_polyline.points') ;

        return PolyUtil::containsLocation($point, $polygon);
    }

    /*
    |--------------------------------------------------------------------------
    | Protected methods
    |--------------------------------------------------------------------------
    |
    */

   /**
    * Get web service polyline parameter being decoded
    * @param $rsp - string
    * @param string $param - response key
    * @return string - JSON
    */
    protected function decode( $rsp, $param = 'routes.overview_polyline.points' ){
        $needle = metaphone($param);

        // get response
        $obj = json_decode( $rsp, true);

        // flatten array into single level array using 'dot' notation
        $obj_dot = Arr::dot($obj);
        // create empty response
        $response = [];
        // iterate
        foreach( $obj_dot as $key => $val){

            // Calculate the metaphone key and compare with needle
            $val =  strcmp( metaphone($key, strlen($needle)), $needle) === 0
                    ? PolyUtil::decode($val) // if matched decode polyline
                    : $val;

                Arr::set($response, $key, $val);
        }

        return json_encode($response, JSON_PRETTY_PRINT) ;
    }
}

ZeroDay Forums Mini