PHP code example of geocoder-php / cache-provider
1. Go to this page and download the library: Download geocoder-php/cache-provider 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/ */
geocoder-php / cache-provider example snippets
$httpClient = new \Http\Discovery\Psr18Client();
$provider = new \Geocoder\Provider\GoogleMaps\GoogleMaps($httpClient);
$psr6Cache = new ArrayCachePool(); // Requires `cache/array-adapter` package
$cachedProvider = new \Geocoder\Provider\Cache\ProviderCache(
$provider, // Provider to cache
$psr6Cache, // PSR-6 compatible cache
600 // Cache expiry, in seconds
);
$geocoder = new \Geocoder\StatefulGeocoder($cachedProvider, 'en');
// Will come from Google Maps API
$result1 = $geocoder->geocodeQuery(GeocodeQuery::create('Buckingham Palace, London'));
// Will come from the cache
$result2 = $geocoder->geocodeQuery(GeocodeQuery::create('Buckingham Palace, London'));