vladshut/postcode-bundle

Symfony Postcode 套件

安装: 313

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 2

类型:symfony-bundle

3.3 2019-05-11 09:17 UTC

This package is auto-updated.

Last update: 2024-09-11 21:15:14 UTC


README

此套件可用于通过邮编数字检索地址详情。需要Apiwise账户。更多信息请参阅:https://www.postcodeapi.nu

Build Status Latest Stable Version License Total Downloads Coverage Status Scrutinizer Code Quality

安装

安装是一个快速的四步过程

  1. 使用composer下载postcode-bundle
  2. 在AppKernel.php中启用Bundle
  3. 配置Apiwise凭证
  4. 添加路由

步骤 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响应

http://127.0.0.1:8000/api/postcode?postcode=2011WD&nummer=2