postcodes io
2.0.1
PostcodesIO 是 postcodes.io API 的 PHP 库。
使用作曲家安装:
$ composer require jabranr/postcodes-io
以下所有方法都会返回与来自 postcodes.io API 的 JSON 格式相同的完整响应。
先决条件
码头工人
启动容器: docker-compose up
运行测试: docker-compose exec postcodes_io bash -c "composer test"
调试Xdebug 已作为 docker 设置的一部分安装并启用。该项目包括 VSCode 的launch.json
调试设置文件。
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
try {
$ addresses = $ postcodesIO -> find ( ' NW1 5LD ' );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
您可以捕获特定的
JabranrPostcodesIOExceptionPostcodeIOException
或/和捕获常规Exception
以捕获任何类型。
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ( ' NW1 5LD ' );
$ addresses = $ postcodesIO -> getResult ();
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> findByLocation ( 51.520331 , - 0.1396267 );
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> findRandom ();
或者使用别名方法:
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> random ();
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> validate ( ' NW1 5LD ' );
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> findNearest ( ' NW1 5LD ' );
或者使用别名方法:
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> nearest ();
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> autocomplete ( ' NW1 ' );
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> query ( ' NW1 5LD ' );
或者使用别名方法:
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> search ( ' NW1 5LD ' );
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> findOutcode ( ' NW1 ' );
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> nearestOutcode ( ' NW1 ' );
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> findOutcodeByLocation ( 51.520331 , - 0.1396267 );
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> bulkPostcodeSearch ( array ( ' NW1 5LD ' , ' W1T 7NY ' ));
每个请求最多 100 个邮政编码。
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> bulkReverseGeocoding ( array (
array ( 51.520331 , - 0.1396267 ),
array ( 51.520331 , - 0.1396267 )
));
或者
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> bulkReverseGeocoding ( array (
array ( ' latitude ' => 51.520331 , ' longitude ' => - 0.1396267 ),
array ( ' latitude ' => 51.520331 , ' longitude ' => - 0.1396267 )
));
每个请求最多 100 个地理位置。
麻省理工学院许可证 © 2016 – 至今 |贾布兰·拉菲克