PostcodesIO é uma biblioteca PHP para API postcodes.io.
Instale usando o compositor:
$ composer require jabranr/postcodes-io
Todos os métodos a seguir retornam a mesma resposta completa proveniente da API postcodes.io no formato JSON.
Pré-requisitos
Docker
Iniciar contêiner: docker-compose up
Execute testes: docker-compose exec postcodes_io bash -c "composer test"
Depuração O Xdebug já está instalado e habilitado como parte da configuração do docker. O projeto inclui o arquivo de configuração de depuração launch.json
para VSCode.
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
try {
$ addresses = $ postcodesIO -> find ( ' NW1 5LD ' );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
Você pode capturar
JabranrPostcodesIOExceptionPostcodeIOException
específico ou/e capturarException
geral para capturar qualquer tipo.
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 ();
OU use o método alias:
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 ' );
OU use o método alias:
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 ' );
OU use o método alias:
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 ' ));
Máximo de 100 códigos postais por solicitação.
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
$ addresses = $ postcodesIO -> bulkReverseGeocoding ( array (
array ( 51.520331 , - 0.1396267 ),
array ( 51.520331 , - 0.1396267 )
));
ou
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 )
));
Máximo de 100 geolocalizações por solicitação.
Licença MIT © 2016 – presente | Jabran Rafique