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 – 至今 |賈布蘭·拉菲克