vladshut / postcode-bundle
Symfony Postcode 套件
3.3
2019-05-11 09:17 UTC
Requires
- php: >=7.2
- ext-json: *
- guzzlehttp/guzzle: ^6.2
- php-http/guzzle6-adapter: ^1.1
- symfony/framework-bundle: >=2.7
- vladshut/postcode-api-client: 1.0
Requires (Dev)
README
此套件可用于通过邮编数字检索地址详情。需要Apiwise账户。更多信息请参阅:https://www.postcodeapi.nu
安装
安装是一个快速的四步过程
- 使用composer下载postcode-bundle
- 在AppKernel.php中启用Bundle
- 配置Apiwise凭证
- 添加路由
步骤 1:使用composer下载postcode-bundle
运行以下命令添加UsoftPostcodeBundle
$ composer require shivella/postcode-bundle
步骤 2:在AppKernel.php中启用Bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Usoft\PostcodeBundle\UsoftPostcodeBundle(), ); }
步骤 3:配置Apiwise凭证
# app/config/config.yml # Apiwise Postcode API usoft_postcode: apiwise: key: secret_api_wise_key
步骤 4. 添加路由
# app/config/routing.yml postcode: resource: "@UsoftPostcodeBundle/Resources/config/routing.yml" prefix: /
服务使用
$address = $this->get('usoft.postcode.client')->getAddress('1012JS', 1); $address->getStreet(); // Dam $address->getCity(); // Amsterdam $address->getMunicipality(); // Amsterdam $address->getProvince(); // Noord-Holland $address->getNumber(); // 1 $address->getZipcode(); // 1012JS $address->getGeoLocation(); // array('latitude' => 52.3732926, 'longitude' => 4.8937176)
通过API使用
或尝试API响应