PostcodesIO est une bibliothèque PHP pour l'API postcodes.io.
Installer à l'aide de Composer :
$ composer require jabranr/postcodes-io
Toutes les méthodes suivantes renvoient la même réponse complète telle qu'elle provient de l'API postcodes.io au format JSON.
Conditions préalables
Docker
Conteneur de démarrage : docker-compose up
Exécuter des tests : docker-compose exec postcodes_io bash -c "composer test"
Débogage Xdebug est déjà installé et activé dans le cadre de la configuration du docker. Le projet comprend le fichier de configuration de débogage launch.json
pour VSCode.
use Jabranr PostcodesIO PostcodesIO ;
$ postcodesIO = new PostcodesIO ();
try {
$ addresses = $ postcodesIO -> find ( ' NW1 5LD ' );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
Vous pouvez intercepter
JabranrPostcodesIOExceptionPostcodeIOException
spécifiques ou/et attraperException
générales pour intercepter n'importe quel type.
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 utilisez la méthode 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 utilisez la méthode 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 utilisez la méthode 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 ' ));
Maximum de 100 codes postaux par demande.
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 )
));
Maximum de 100 géolocalisations par demande.
Licence MIT © 2016 – présent | Jabran Rafique