2017 © Pedro Pelรกez
 

library google-map-polyline-encoding-tool

A simple class to handle polyline-encoding for Google Maps

image

emcconville/google-map-polyline-encoding-tool

A simple class to handle polyline-encoding for Google Maps

  • Wednesday, June 1, 2016
  • by emcconville
  • Repository
  • 6 Watchers
  • 106 Stars
  • 182,325 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 28 Forks
  • 2 Open issues
  • 8 Versions
  • 11 % Grown

The README.md

Google Maps Polyline Encoding Tool

Build Status Coverage Status Packagist Version, (*1)

A simple PHP class for translating polyline into an encoded strings for Google Maps., (*2)

Install

Use composer., (*3)

$ curl -sS https://getcomposer.org/installer | php
$ cat > composer.json <<EOF
{
   "require": {
      "emcconville/google-map-polyline-encoding-tool" : ">=1.2.1"
   }
}
EOF
$ php composer.phar install

Old fashion way., (*4)

$ git clone git://github.com/emcconville/google-map-polyline-encoding-tool.git
$ cp src/Polyline.php /path/to/your/application/includes/Polyline.php

Usage

Encoding

// Points to encode
$points = array(
        array(41.89084,-87.62386),
        array(41.89086,-87.62279),
        array(41.89028,-87.62277),
        array(41.89028,-87.62385),
        array(41.89084,-87.62386)
    );

$encoded = Polyline::encode($points);
//=> wxt~Fd`yuOCuErBC?vEoB@

Tribune, (*5)

Decoding

// String to decode
$encoded = "kiw~FpoavObBA?fAzEC";

$points = Polyline::decode($encoded);
//=> array(
//     41.90374,-87.66729,41.90324,-87.66728,
//     41.90324,-87.66764,41.90214,-87.66762
//   );

// Or list of tuples
$points = Polyline::pair($points);
//=> array(
//     array(41.90374,-87.66729),
//     array(41.90324,-87.66728),
//     array(41.90324,-87.66764),
//     array(41.90214,-87.66762)
//   );

Records, (*6)

Examples

See examples directory for creative ideas, and please contribute new use-cases / hacks., (*7)

Specify precision

Precision defaults to 1e-5 (0.00001) which is expected by Google Map API. Other API's like OSRM expect a precision of 1e-6. You can adjust the precision you want by sub-classing Polyline, and overwrite the $precision static property., (*8)

class PolylineOSRM extends Polyline
{
    protected static $precision = 6;
}
$points = PolylineOSRM::decode($line);
$line = PolylineOSRM::encode($points);

Caution, (*9)

  • Adjusting the precision level will not guarantee improved accuracy. Existing issues with PHP's internal float point arithmetic can contribute accuracy issues.
  • Third party libraries will not automatically know what level of precision was used during encoding.

Family

This library exists as a PHP reference point for Google's Encoded Polyline Algorithm Format. There is also a C implementation, and a namespace/trait library under active development., (*10)

Requires google-map-polyline-encoding-tool polyline-encoder php_polyline
PHP 5.3 5.4 C-API
Supports google-map-polyline-encoding-tool polyline-encoder php_polyline
Google โœ” โœ” โœ”
Bing โœ”
Precision โœ” โœ” โœ”
Tuple โœ” โœ”
Traits โœ”
Abstraction โœ”

The Versions

01/06 2016

dev-master

9999999-dev

A simple class to handle polyline-encoding for Google Maps

  Sources   Download

GNU

The Requires

  • php >=5.3

 

The Development Requires

by Eric McConville

google maps

05/04 2016

v1.3

1.3.0.0

A simple class to handle polyline-encoding for Google Maps

  Sources   Download

GNU

The Requires

  • php >=5.3

 

The Development Requires

by Eric McConville

google maps

20/03 2015

dev-pu

dev-pu

A simple class to handle polyline-encoding for Google Maps

  Sources   Download

GNU

The Requires

  • php >=5.3

 

The Development Requires

by Eric McConville

google maps

04/01 2015

v1.2.4

1.2.4.0

A simple class to handle polyline-encoding for Google Maps

  Sources   Download

GNU

The Requires

  • php >=5.3

 

The Development Requires

by Eric McConville

google maps

08/08 2014

v1.2.3

1.2.3.0

A simple class to handle polyline-encoding for Google Maps

  Sources   Download

GNU

The Requires

  • php >=5.3

 

The Development Requires

by Eric McConville

google maps

03/08 2014

v1.2.2

1.2.2.0

A simple class to handle polyline-encoding for Google Maps

  Sources   Download

GNU

The Requires

  • php >=5.3

 

The Development Requires

by Eric McConville

google maps

13/07 2014

v1.2.1

1.2.1.0

A simple class to handle polyline-encoding for Google Maps

  Sources   Download

GNU

The Requires

  • php >=5.3

 

The Development Requires

by Eric McConville

google maps

17/03 2014

v1.2

1.2.0.0

A simple class to handle polyline-encoding for Google Maps

  Sources   Download

GNU

The Requires

  • php >=5.3

 

by Eric McConville

google maps