Skip to content
PHP Traits algorithms for Encoded Polyline & Bing Point Compression
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build
src/emcconville/Polyline
test
.coveralls.yml
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml.dist

README.md

Polyline Encoder

Build Status Latest Stable Version License

Formerly emcconville/google-map-polyline-encoding-tool, this library provides encoding/decoding methods for Google Map's Encoded Polyline, and Microsoft's Point Compression Algorithm. The intent of the Polyline Encoder library is to shift the core algorithms to PHP Traits over traditional class implementations.

Installation

Add emcconville/polyline-encoder to composer's required list.

{
  "require" : {
    "emcconville/polyline-encoder" : "1.*"
  }
}

Follow basic composer installation & guide.

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

Usage

Both BingTrait & GoogleTrait cover the same two methods.

string <object>::encodePoints( array $points )

// 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"

array <object>::decodeString( string $string )

// 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)

Goolge Map


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

Bing Map


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

OSRM Map

// 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;
  }
}
You can’t perform that action at this time.