Query geographic reference data more easily using offline data from Gouv administrative division API.
- Query all departments data
- Query all municipalities by department code
cvilleger/geo-gouv
requires at least PHP 8.2
Install this package as a dependency using Composer.
composer require cvilleger/geo-gouv
use Cvilleger\GeoGouv\Client;
$client = new Client();
$departements = $client->getDepartements();
print_r($departements[0]);
/*
Cvilleger\GeoGouv\Model\Departement Object
(
[nom] => Ain
[code] => 01
[codeRegion] => 84
[region] => Cvilleger\GeoGouv\Model\Region Object
(
[nom] => Auvergne-Rhône-Alpes
[code] => 84
)
)
*/
use Cvilleger\GeoGouv\Client;
$client = new Client();
$communes = $client->getCommunesByDepartementCode('01');
print_r($communes[0]);
/*
(
[nom] => L'Abergement-Clémenciat
[code] => 01001
[codesPostaux] => Array
(
[0] => 01400
)
[centre] => Cvilleger\GeoGouv\Model\Centre Object
(
[type] => Point
[coordinates] => Array
(
[0] => 4.9306
[1] => 46.1517
)
)
[surface] => 1564.5
[population] => 832
[departement] => Cvilleger\GeoGouv\Model\CommuneDepartement Object
(
[nom] => Ain
[code] => 01
)
[region] => Cvilleger\GeoGouv\Model\CommuneRegion Object
(
[nom] => Auvergne-Rhône-Alpes
[code] => 84
)
)
*/