PHP code example of label84 / php-nederland-postcode
1. Go to this page and download the library: Download label84/php-nederland-postcode library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
label84 / php-nederland-postcode example snippets
use Label84\NederlandPostcode\NederlandPostcodeClient;
$client = new NederlandPostcodeClient(
key: 'npa_live_XXX',
);
try {
$address = $client->find(
postcode: '1118BN',
number: 800,
attributes: ['coordinates'],
);
} catch (NederlandPostcodeException $exception) {
// handle exception
}
echo $address->street; // Schiphol Boulevard
echo $address->coordinates->latitude; // 52.30703569036619
use Label84\NederlandPostcode\NederlandPostcodeClient;
$client = new NederlandPostcodeClient(
key: 'npa_live_XXX'
);
$address = $client->find(
postcode: '1118BN',
number: 800,
addition: null,
attributes: [
AddressAttributesEnum::COORDINATES,
],
);
Address {
postcode: "1118BN",
number: 800,
addition: null,
street: "Schiphol Boulevard",
city: "Schiphol",
municipality: "Haarlemmermeer",
province: "Noord-Holland",
coordinates: Coordinates {
latitude: 52.30528553688755,
longitude: 4.750645160863609
},
district: District {
official: "Schiphol",
name: "Schiphol"
},
function: "kantoorfunctie",
location_status: "verblijfsobject in gebruik",
property_status: "pand in gebruik",
surface_area: 10398.0,
construction_year: 2019
}
use Label84\NederlandPostcode\NederlandPostcodeClient;
$client = new NederlandPostcodeClient(
key: 'npa_live_XXX'
);
$addresses = $client->list(
postcode: '1015CN',
number: 10,
addition: null,
attributes: ['coordinates'],
);
AddressCollection {
items: [
Address {
postcode: "1015CN",
number: 10,
addition: "A",
street: "Keizersgracht",
city: "Amsterdam",
municipality: "Amsterdam",
province: "Noord-Holland",
country: "Nederland",
coordinates: Coordinates { ... }
...
},
Address {
postcode: "1015CN",
number: 10,
addition: "B",
street: "Keizersgracht",
...
}
]
}
use Label84\NederlandPostcode\NederlandPostcodeClient;
$client = new NederlandPostcodeClient(
key: 'npa_live_XXX'
);
$energyLabels = $client->energyLabels()->get(
postcode: '1118BN',
number: 800,
addition: null,
);
EnergyLabelCollection {
items: [
EnergyLabel {
postcode: "1118BN",
number: 800,
addition: null,
street: "Schiphol Boulevard",
city: "Schiphol",
inspectionDate: DateTime("2022-08-02"),
validUntilDate: DateTime("2032-08-02"),
constructionType: "utiliteitsbouw",
buildingType: null,
energyLabel: "A+++",
maxEnergyDemand: 98.4,
maxFossilEnergyDemand: 55.48,
minRenewableShare: 55.3
}
]
}
use Label84\NederlandPostcode\NederlandPostcodeClient;
$client = new NederlandPostcodeClient(
key: 'npa_live_XXX'
);
$quota = $client->usage();
Quota {
used: 1500,
limit: 10000,
}
use Label84\NederlandPostcode\Exceptions\NederlandPostcodeException;
$client = new NederlandPostcodeClient(
key: 'npa_live_XXX'
);
try {
$addresses = $client->find(
postcode: 'INVALID',
number: 123,
addition: null,
);
} catch (NederlandPostcodeException $exception) {
// handle error
}
bash
composer