adrianoalves / google-geolocation
使用Google Geo API的简单、节省资源、框架无关、轻量级和原生PHP地理定位服务
1.2
2020-11-09 03:53 UTC
Requires
- php: >7.2
Requires (Dev)
- phpunit/phpunit: ^9
README
使用原生PHP实现的节省资源、轻量级、框架无关的Google地理定位服务
我们能做什么
-
使用地理编码器获取可读地址的经纬度坐标;
-
根据路径和骑行模式,计算两个物理点之间的距离和时间。
开始使用
如何安装
您可以克隆此存储库或使用composer安装此包
composer require adrianoalves/google-geolocation
在开始使用此包之前,您需要一个API密钥,注册为Google开发者,创建一个带有计费账户的项目并生成您的API密钥。了解更多信息,请访问官方Google文档。
- 使用地理编码器
// a simplest example $geoCoder = new \Geolocation\GeoCoder\GeoCoder( 'yoUr-aPiKey-hEre' ); // getting the latitude and longitude of an address $result = $geoCoder->request( 'Praça da Sé, São Paulo, SP' ); var_dump( $result );
- 使用距离矩阵
// same simplest example here $distanceMatrix = new \Geolocation\DistanceMatrix\DistanceMatrix( 'yoUr-aPiKey-hEre' ); // getting the distance in metrics and the time in seconds from an address to another $result = $distanceMatrix->request( ['Praça da Sé, São Paulo, SP'], ['Avenida Paulista, 1, São Paulo, SP'] ); var_dump( $result );
有一个示例目录,您可以在这里了解如何轻松使用它。
我非常欢迎任何建议、批评、评论和错误报告,请告诉我。