emcconville / polyline-encoder
PHP Traits algorithms for Encoded Polyline & Bing Point Compression
Installs: 192 196
Dependents: 2
Suggesters: 0
Security: 0
Stars: 29
Watchers: 6
Forks: 3
Open Issues: 0
Requires
- php: >=5.4
Replaces
This package is not auto-updated.
Last update: 2024-11-23 16:34:49 UTC
README
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; } }