1. Go to this page and download the library: Download naif/saudiaddress 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/ */
use Naif\Saudiaddress\Facades\SaudiAddress;
$regions = SaudiAddress::regions();
// In English
$regions = SaudiAddress::regions('E');
// All cities
$cities = SaudiAddress::cities();
// Cities in a specific region
$cities = SaudiAddress::cities(1);
// In English
$cities = SaudiAddress::cities(1, 'E');
// Districts within a city
$districts = SaudiAddress::districts(3);
// In English
$districts = SaudiAddress::districts(3, 'E');
use Naif\Saudiaddress\Exceptions\SaudiAddressException;
use Naif\Saudiaddress\Exceptions\ApiRequestException;
use Naif\Saudiaddress\Exceptions\InvalidResponseException;
use Naif\Saudiaddress\Exceptions\AddressNotFoundException;
use Naif\Saudiaddress\Exceptions\InvalidConfigurationException;
try {
$address = SaudiAddress::geoCode(24.774265, 46.738586);
} catch (AddressNotFoundException $e) {
// No address found at these coordinates
} catch (ApiRequestException $e) {
// Network error or API returned an error
} catch (InvalidResponseException $e) {
// API returned unexpected data
} catch (SaudiAddressException $e) {
// Catch-all for any Saudi Address related error
}