sgoranov / google-maps-tools
Google Maps API 的 PHP 封装器
此包的规范仓库似乎已不存在,因此该包已被冻结。
dev-master
2016-08-23 12:42 UTC
Requires
- php: >=5.6.0
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ~4.1
This package is not auto-updated.
Last update: 2024-01-20 14:26:22 UTC
README
Google Maps API 的 PHP 封装器
作者
Simeon Goranov - sgoranov@gmail.com
安装
更新你的 composer.json,添加以下内容
$ composer require sgoranov/google-maps-tools
使用方法
使用 Google Maps Geocoding API 调用来通过地址搜索
$geocode = new Geocode('Car Osvoboditel 13, Sofia, Bulgaria'); $geocode->execute(); $point = $geocode->getFirstPoint();
点由纬度和经度定义
$latitude = $point->getLatitude(); $longitude = $point->getLongitude();
使用 Google Maps Distancematrix API 调用来计算两点之间的距离
$dmatrix = new Distancematrix($startPoint, $endPoint); try { $result = $dmatrix->fetch(); } catch (ApiException $e) { throw new \InvalidArgumentException('Unable to calculate the distance'); }
使用 DistanceCalc 库来计算多个点之间的距离
$calc = new DistanceCalc(); $geocode = new Geocode('Car Osvoboditel 13, Sofia, Bulgaria'); $geocode->execute(); $point = $geocode->getFirstPoint(); $calc->addPoint($point); $geocode = new Geocode('Ianko Sakazov 1, Sofia, Bulgaria'); $geocode->execute(); $point = $geocode->getFirstPoint(); $calc->addPoint($point); $geocode = new Geocode('Georgi Rakovski 96, Sofia, Bulgaria'); $geocode->execute(); $point = $geocode->getFirstPoint(); $calc->addPoint($point); $distance = $calc->calculate();
单元测试
要本地运行测试,执行以下操作
vendor/phpunit/phpunit/phpunit