emcconville/google-map-polyline-encoding-tool
Composer 安装命令:
composer require emcconville/google-map-polyline-encoding-tool
包简介
A simple class to handle polyline-encoding for Google Maps
README 文档
README
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 <<EOF
{
"require": {
"emcconville/google-map-polyline-encoding-tool" : ">=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`yuOCuErBC?vEoB@
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) // );
Examples
See examples directory for creative ideas, and please contribute new use-cases / hacks.
- Well-Known Binary converter.
- Preview encoded strings with a SVG transcoder.
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 |
|---|---|---|---|
| ✔ | ✔ | ✔ | |
| Bing | ✔ | ||
| Precision | ✔ | ✔ | ✔ |
| Tuple | ✔ | ✔ | |
| Traits | ✔ | ||
| Abstraction | ✔ |
emcconville/google-map-polyline-encoding-tool 适用场景与选型建议
emcconville/google-map-polyline-encoding-tool 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.38M 次下载、GitHub Stars 达 157, 最近一次更新时间为 2013 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「google」 「maps」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 emcconville/google-map-polyline-encoding-tool 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 emcconville/google-map-polyline-encoding-tool 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 emcconville/google-map-polyline-encoding-tool 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova Google Maps Field.
Google Maps PHP SDK.
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
A Google Maps library for WordPress.
An easy way to integrate Google Maps with Laravel.
Google Maps API for Laravel
统计信息
- 总下载量: 2.38M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 157
- 点击次数: 21
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: GNU
- 更新时间: 2013-11-29