Skip to content

Commit 0aa8452

Browse files
committed
Updated: doc with an exemple of the ChainProvider
1 parent e2e9554 commit 0aa8452

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,33 @@ Parameters:
308308
* `$useSsl` is available for `GoogleMapsProvider`, `GoogleMapsBusinessProvider`, `MaxMindProvider` and `ArcGISOnlineProvider`.
309309
* `$sourceCountry` is available for `ArcGISOnlineProvider`.
310310

311+
312+
### Using The ChainProvider ###
313+
314+
As said it's a special provider that takes a list of providers and iterates over this list to get information. Note
315+
that it **stops** its iteration when a provider returns a result. The result is returned by `GoogleMapsProvider`
316+
because `FreeGeoIpProvider` and `HostIpProvider` cannot geocode street addresses. `YahooProvider` is ignored.
317+
318+
``` php
319+
$geocoder = new \Geocoder\Geocoder();
320+
$adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
321+
$chain = new \Geocoder\Provider\ChainProvider(array(
322+
new \Geocoder\Provider\FreeGeoIpProvider($adapter),
323+
new \Geocoder\Provider\HostIpProvider($adapter),
324+
new \Geocoder\Provider\GoogleMapsProvider($adapter, 'fr_FR', 'France', true),
325+
new \Geocoder\Provider\YahooProvider($adapter, '<API_KEY>', 'fr_FR'),
326+
// ...
327+
));
328+
$geocoder->registerProvider($chain);
329+
330+
try {
331+
$geocode = $geocoder->geocode('10 rue Gambetta, Paris, France');
332+
var_export($geocode);
333+
} catch (Exception $e) {
334+
echo $e->getMessage();
335+
}
336+
```
337+
311338
Everything is ok, enjoy!
312339

313340
API
@@ -526,7 +553,7 @@ You can also write your own `provider` by implementing the `ProviderInterface`.
526553

527554
You can provide your own `result` by extending `ResultFactory` and implementing `ResultInterface` if your provider returns more informations than the default one.
528555

529-
Note, `AbstractProvider` and `AbstractResult` clasess can help you by providing useful features.
556+
Note, `AbstractProvider` and `AbstractResult` classes can help you by providing useful features.
530557

531558
You can provide your own `dumper` by implementing the `DumperInterface`.
532559

0 commit comments

Comments
 (0)