suilven/ukpostcodes
Composer 安装命令:
composer require suilven/ukpostcodes
包简介
Wrapper around postcodes.io to get info about UK postcodes
README 文档
README
PHP client wrapper around the postcodes.io API service
Usage
Getting a PostCode
$postcode = PostCodeFactory::get('KY16 9SS');
or
$api = new Suilven\UKPostCodes\API(); $lookup = $this->api->lookup('KY16 9SS'');
Getting Nearby PostCodes
$postcode = PostCodeFactory::get('KY16 9SS'); $nearby = $postcode->nearest();
or
$api = new Suilven\UKPostCodes\API(); $nearest = $this->api->nearest('SW1A 2AA');
Bulk Lookup By PostCode
$api = new Suilven\UKPostCodes\API(); $postcodeObjects = $this->api->bulkLookup([ 'SW1A 2AA', 'KY16 9SS', 'KY11 3ED' ]);
Bulk Lookup By Coordinates
$api = new Suilven\UKPostCodes\API(); $coors = [ [ 'latitude' => 51.50354, 'longitude' => -0.127695, ], [ 'latitude' => 56.340349, 'longitude' => -2.808787, ], [ 'latitude' => 56.03587, 'longitude' => -3.500364, ], ]; $bulkReversed = $this->api->bulkReverseGeocoding($coors);
Bulk Lookup By Coordinates
Note that if the coordinates are outside of the UK, an empty array is returned by the API.
$api = new Suilven\UKPostCodes\API(); $postcodeObjects = $this->api->nearestPostcodesFromLongLat(0.629834723775309, 51.7923246977375);
Lookup Up A Terminated PostCode
Note that this will return a partially populated PostCode object.
$api = new Suilven\UKPostCodes\API(); $terminated = $this->api->lookupTerminated('AB1 0AA');
Lookup an Outward Code
An outcode is the part of a postcode prior to the space, e.g. KY16 in KY16 9SS
$api = new Suilven\UKPostCodes\API(); $lookup = $this->api->lookupOutwardCode('RH1');
Lookup Outward Code By Coordinates
$api = new Suilven\UKPostCodes\API(); $lookup = $this->api->nearestOutwardCodeFromLongLat(0.629834723775309, 51.7923246977375);
Find the Nearest Outward Code to a Given Outward Code
$api = new Suilven\UKPostCodes\API(); $nearest = $this->api->nearestOutwardCode('RH1');
Autocomplete a PostCode
$api = new Suilven\UKPostCodes\API(); $autocompletedPostCodes = $this->api->partial('SW16');
Query a Partial PostCode
$api = new Suilven\UKPostCodes\API(); $postcodeObjs = $this->api->query('SW16');
Get a Random Postcode
$api = new Suilven\UKPostCodes\API(); $random = $this->api->random();
Get Distance Between Two PostCodes
$api = new Suilven\UKPostCodes\API(); $distance = $this->api->distance('SW1A 2AB', 'EH99 1SP', Distance::KM);
If the distance units parameter is not provided, then the default is miles (MILES). The other option is NAUTICAL_MILES.
Check if a PostCode is Valid or Not
$api = new Suilven\UKPostCodes\API(); // false as there is no space in the postcode $validated = $this->api->validate('KYAB92A');
Docker Dev Environment
Starting
Note that the first time this is executed the container will be built.
sudo docker-compose up -d phpcli
Getting A Bash Prompt
sudo docker-compose exec phpcli /bin/bash
Running Tests Locally
root@ukpostcodes.dev:/var/www> vendor/bin/phpunit tests/
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
.................................. 34 / 34 (100%)
Time: 156 ms, Memory: 6.00 MB
Generating Test Coverage
phpdbg -qrr vendor/bin/phpunit -d memory_limit=4G --coverage-html report tests/
suilven/ukpostcodes 适用场景与选型建议
suilven/ukpostcodes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 suilven/ukpostcodes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 suilven/ukpostcodes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-07