shivella/postcode-bundle

Symfony Postcode 包

安装次数: 2,863

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 2

开放性问题: 0

类型:symfony-bundle

1.0.7 2021-03-13 19:38 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:58:34 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. 添加路由

第一步:使用composer下载postcode-bundle

运行命令添加UsoftPostcodeBundle

$ composer require shivella/postcode-bundle

第二步:在AppKernel.php中启用Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Usoft\PostcodeBundle\UsoftPostcodeBundle(),
    );
}

第三步:配置Apiwise凭据

# app/config/config.yml

# Apiwise Postcode API
usoft_postcode:
    apiwise:
        key: secret_api_wise_key

第四步:添加路由

# 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