PHP code example of cvilleger / geo-gouv
1. Go to this page and download the library: Download cvilleger/geo-gouv 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/ */
cvilleger / geo-gouv example snippets
use Cvilleger\GeoGouv\Client;
print_r(new Client()->getDepartements()[0]);
/*
Cvilleger\GeoGouv\Model\Departement Object
(
[nom] => Ain
[code] => 01
[codeRegion] => 84
[coordinates] => 46.06551335, 5.28478031423462
[region] => Cvilleger\GeoGouv\Model\Region Object
(
[nom] => Auvergne-Rhône-Alpes
[code] => 84
)
)
*/
use Cvilleger\GeoGouv\Client;
print_r(new Client()->getCommunesByDepartementCode('01')[0]);
/*
(
[nom] => L'Abergement-Clémenciat
[code] => 01001
[codesPostaux] => Array
(
[0] => 01400
)
[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
)
)
*/