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.
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
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)
// 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;
}
}