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/test.tradze.com/vendor/alexpechkarev/google-maps/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

/**
 * Description of GoogleMaps
 *
 * @author Alexander Pechkarev <alexpechkarev@gmail.com>
 */

use GeometryLibrary\PolyUtil;

class Directions extends \GoogleMaps\WebService{
    
     
    
    
    /**
     * Get Web Service Response
     * @return type
     */
    public function get( $needle = false ){
        
        // is decodePolyline true?  set endpoint to json
        if( $this->service['decodePolyline'] ){
            $this->setEndpoint('json');
        }
        
        
        return $this->service['decodePolyline']
                    ? $this->decode( parent::get( $needle ) )
                    : 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 $tolrance
     * @return boolean
     */
    public function isLocationOnEdge( $lat, $lng, $tolrance = 0.1){
        
        $point = [
            'lat' => $lat,
            'lng' => $lng
        ];
        
        $polygon = array_get( json_decode( $this->get(), true ), 'routes.0.overview_polyline.points') ;
        
        return PolyUtil::isLocationOnEdge($point, $polygon, $tolrance);
       
    }
    /***/
    
    /**
     * 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
     */
    public function containsLocation($lat, $lng){
        
        $point = [
            'lat' => $lat,
            'lng' => $lng
        ];  
        
        $polygon = array_get( json_decode( $this->get(), true ), 'routes.0.overview_polyline.points') ;      
        
        return PolyUtil::containsLocation($point, $polygon);        
    }
    /***/
    
    /*
    |--------------------------------------------------------------------------
    | Protected methods
    |--------------------------------------------------------------------------
    |
    */    
    
   /**
    * Get web wervice 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 = array_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;
            
                array_set($response, $key, $val);
        }        
        

        return json_encode($response, JSON_PRETTY_PRINT) ;

        
        
    }
    /***/     
       
      
}

ZeroDay Forums Mini