alexsawallich / zend-google-geocoder
一个提供查询Google Geocoder API的小服务类的Zend-Framework-Module。结果可以选择性地缓存以避免遇到API的查询限制。
Requires
- php: >=5.5
This package is auto-updated.
Last update: 2024-08-29 03:58:05 UTC
README
ZendGoogleGeocoder是一个Zend Framework 2模块,它提供了一个查询Google Geocoding API的服务。此模块允许您从您的ServiceLocator中检索服务,并使用方法检索提供的地址/位置的地理坐标。
该模块包含一个API客户端,它使用file_get_contents
或cURL
从Google的API请求数据。
使用Zend\Log
对查询API的工作流程中的每个步骤进行文档记录。然而,默认情况下,使用Zend\Log\Writer\Noop-Writer禁用了日志记录,您可以通过覆盖特定的配置键来更改它(有关更多详细信息,请参阅Wiki)。
为了避免遇到配额限制,Google的API的响应正在被缓存[未完成]。
使用示例
更多示例可以在Wiki中找到。
// For example in an action-method $address = $this->getRequest()->getPost('address'); $geocoderService = $this->getServiceLocator()->get('ZendGoogleGeocoderService'); $response = $geocoderService->geocodeAddress($address, $format = 'xml'); // Do something with the response here...
安装
步骤 1: 获取文件
通常您有三种典型的安装模块的方法。
步骤 1a: Composer首选方法是用composer。模块的名称是alexsawallich/zend-google-geocoder
。因此,您可以将它放在composer.json的require
部分,如下所示
"require": {
// ... more here
"alexsawallich/zend-google-geocoder": "dev-master",
// ... more here
}
或者您可以在命令行中这样添加
$ php composer.phar require "alexsawallich/zend-google-geocoder"
完成后,运行composer update命令
$ php composer.phar update
步骤 1b: Git克隆
在命令行中,转到您的应用程序的vendor
目录,并运行git clone
命令
$ cd /path/to/my/project/vendor
$ git clone https://github.com/alexsawallich/ZendGoogleGeocoder.git
% 如果您有一个基于UI的客户端(如GitHub for Windows),您可能知道要点击哪些按钮。
步骤 1c: 手动下载
尽管这有点过时,而且您无法通过composer更新模块,但您当然可以手动从这个GitHub页面下载ZIP文件,并将解压的文件夹放入您的vendor
或modules
目录。
步骤 2: 配置
在获取文件后,您需要在您的application.config.php
文件中启用模块。
// application.config.php return array( 'modules' => array( 'ZendGoogleGeocoder' // ...
现在进入ZendGoogleGeocoder目录,并将config/geocoder.global.php.dist
复制到root-of-your-project/config/geocoder.global.php
。打开文件并根据需要配置可用选项。
现在您应该能够使用该模块了。
特性 / 待办事项 / 路线图
- 查询Google Geocoder API的可能性[已完成]
- 提供API密钥以供API请求使用[已完成]
- 通过提供地址查询API[已完成]
- 通过提供组件(由Google的API定义)查询API[未完成]
- 详细的日志记录可能性[已完成]
- 缓存请求以避免遇到配额限制的可能性[未完成]
关于Google TOS的通知
如果您阅读了Google Geocoding API的文档,您将找到以下内容(来源)
Google Maps 地理编码 API 仅可与 Google 地图配合使用;禁止在不显示地图的情况下使用地理编码结果。有关允许使用的完整详情,请参阅 Maps API 服务条款和许可限制。
请记住这一点!