PHP code example of emcconville / polyline-encoder

1. Go to this page and download the library: Download emcconville/polyline-encoder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

emcconville / polyline-encoder example snippets


// Convert list of points into encoded string.
$points = [
  [41.89084,-87.62386],
  [41.89086,-87.62279],
  [41.89028,-87.62277],
  [41.89028,-87.62385],
  [41.89084,-87.62386]
];

$googleObject->encodePoints($points); //=> "wxt~Fd`yuOCuErBC?vEoB@"
$bingObject->encodePoints($points);   //=> "yg7qol5jxJjqX3iH01W5sG"

// Restore list from encode string.
$points = $googleObject->decodeString("wxt~Fd`yuOCuErBC?vEoB@");
$points[3]; //=> array(41.89028,-87.62385)
$points = $bingObject->decodeString("yg7qol5jxJjqX3iH01W5sG");
$points[4]; //=> array(41.89084,-87.62386)


// Apply Google Trait.
class MyGooglePolyline
{
  use emcconville\Polyline\GoogleTrait;
}



// Apply Bing Trait.
class MyBingPolyline
{
  use emcconville\Polyline\BingTrait;
}


// Apply Google Trait with precision overwrite.
class MyProjectOsrmPolyline
{
  use emcconville\Polyline\GoogleTrait;
  
  /**
   * Implement precision method in sub-class.
   * @return int
   */
  public function polylinePrecision()
  {
      return 6;
  }
}

bash
curl -sS https://getcomposer.org/installer | php
./composer.phar install