Need help with google-map-polyline-encoding-tool?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

emcconville
133 Stars 38 Forks Other 104 Commits 2 Opened issues

Description

A simple class to handle polyline-encoding for Google Maps

Services available

!
?

Need anything else?

Contributors list

# 76,016
C
Perl
Shell
imagema...
81 commits
# 25,935
aws-s3
Apache ...
sasl
bucket
6 commits
# 24,003
Postgre...
testing...
stocks
MySQL
1 commit
# 612,915
autopre...
PHP
php-cur...
curl
1 commit
# 164,339
flat-fi...
Markdow...
reposit...
hugo
1 commit
# 113,004
PHP
Ruby
geocodi...
lets-en...
1 commit
# 744,668
PHP
1 commit

Google Maps Polyline Encoding Tool

Build Status Coverage Status Packagist Version

A simple PHP class for translating polyline into an encoded strings for Google Maps.

Install

Use composer.

$ curl -sS https://getcomposer.org/installer | php
$ cat > composer.json <=1.2.1"
   }
}
EOF
$ php composer.phar install

Old fashion way.

$ 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`[email protected]

Tribune

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

Examples

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

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.
class PolylineOSRM extends Polyline
{
    protected static $precision = 6;
}
$points = PolylineOSRM::decode($line);
$line = PolylineOSRM::encode($points);

Caution

  • 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.

|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| |✔ | |

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.