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
php
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
)
)
*/
php
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
)
)
*/