'),
new \Geocoder\Provider\ArcGISOnline\ArcGISOnline($client),
]);
$geocoder->registerProvider(new \Geocoder\Provider\Nominatim\Nominatim($adapter, 'https://your.nominatim.server'));
$geocoder
->using('google_maps')
->geocodeQuery(GeocodeQuery::create( ... ));
$geocoder
->limit(10)
->reverseQuery(ReverseQuery::fromCoordinates($lat, $lng));
```
The `ProviderAggregator`'s API is fluent, meaning you can write:
```php
use Geocoder\Query\GeocodeQuery;
$locations = $geocoder
->registerProvider(new \My\Provider\Custom($adapter))
->using('custom')
->limit(10)
->geocodeQuery(GeocodeQuery::create( ... ));
```
The `using()` method allows you to choose the `provider` to use by its name.
When you deal with multiple providers, you may want to choose one of them. The
default behavior is to use the first one but it can be annoying.
The `limit()` method allows you to configure the maximum number of results being
returned. Depending on the provider you may not get as many results as expected,
it is a maximum limit, not the expected number of results.
### TimedGeocoder
The `TimedGeocoder` class profiles each `geocode` and `reverse` call. So you can
easily figure out how many time/memory was spent for each geocoder/reverse call.
```php
use Geocoder\Query\GeocodeQuery;
// configure your provider
$provider = // ...
$stopwatch = new \Symfony\Component\Stopwatch\Stopwatch();
$geocoder = new \Geocoder\TimedGeocoder($provider, $stopwatch);
$geocoder->geocodeQuery(GeocodeQuery::create('Paris, France'));
// Now you can debug your application
```
We use the [symfony/stopwatch](http://symfony.com/doc/current/components/stopwatch.html)
component under the hood. Which means, if you use the Symfony framework the
geocoder calls will appear in your timeline section in the Web Profiler.
### StatefulGeocoder
The `StatefulGeocoder` class is great when you want your Geocoder to hold state. Say you want to configure locale,
limit or bounds in runtime. The `StatefulGeocoder` will append these values on each query.
```php
use Geocoder\Query\GeocodeQuery;
// configure your provider
$provider = // ...
$geocoder = new \Geocoder\StatefulGeocoder($provider);
$geocoder->setLocale('en');
$results = $geocoder->geocodeQuery(GeocodeQuery::create('London'));
echo $results->first()->getLocality(); // London
$geocoder->setLocale('es');
$results = $geocoder->geocodeQuery(GeocodeQuery::create('London'));
echo $results->first()->getLocality(); // Londres
```
## Dumpers
**Geocoder** provides dumpers that aim to transform a `Location` object in
standard formats.
### GPS eXchange Format (GPX)
The **GPS eXchange** format is designed to share geolocated data like point of
interests, tracks, ways, but also coordinates. **Geocoder** provides a dumper to
convert a `Location` object in an GPX compliant format.
Assuming we got a `$location` object as seen previously:
```php
$dumper = new \Geocoder\Dumper\Gpx();
$strGpx = $dumper->dump($location);
echo $strGpx;
```
It will display:
```xml
```
### GeoJSON
[GeoJSON](http://geojson.org/) is a format for encoding a variety of geographic
data structures.
### GeoArray
Simple PHP array format for using with your own encoders.
### Keyhole Markup Language (KML)
[Keyhole Markup Language](http://en.wikipedia.org/wiki/Keyhole_Markup_Language)
is an XML notation for expressing geographic annotation and visualization within
Internet-based, two-dimensional maps and three-dimensional Earth browsers.
### Well-Known Binary (WKB)
The Well-Known Binary (WKB) representation for geometric values is defined by
the OpenGIS specification.
### Well-Known Text (WKT)
Well-known text (WKT) is a text markup language for representing vector geometry
objects on a map, spatial reference systems of spatial objects and
transformations between spatial reference systems.
## Formatters
A common use case is to print geocoded data. Thanks to the `StringFormatter`
class, it's simple to format a `Location` object as a string:
```php
// $location is an instance of Location
$formatter = new \Geocoder\Formatter\StringFormatter();
$formatter->format($location, '%S %n, %z %L');
// 'Badenerstrasse 120, 8001 Zuerich'
$formatter->format($location, '%S %n, %z %L
');
// 'Badenerstrasse 120, 8001 Zuerich
'
```
Here is the mapping:
* Street Number: `%n`
* Street Name: `%S`
* City (Locality): `%L`
* City District (Sub-Locality): `%D`
* Zipcode (Postal Code): `%z`
* Admin Level Name: `%A1`, `%A2`, `%A3`, `%A4`, `%A5`
* Admin Level Code: `%a1`, `%a2`, `%a3`, `%a4`, `%a5`
* Country: `%C`
* Country Code: `%c`
* Timezone: `%T`
## Versioning
Geocoder follows [Semantic Versioning](http://semver.org/).
### End Of Life
#### 1.x
As of December 2014, branch `1.7` is not officially supported anymore, meaning
major version `1` reached end of life. Last version is:
[1.7.1](https://github.com/geocoder-php/Geocoder/releases/tag/1.7.1).
#### 2.x
As of December 2014, version [2.x](https://github.com/geocoder-php/Geocoder/tree/2.x)
is in a **feature frozen** state. All new features should be contributed to version 3.0
and upper. Last version is:
[2.8.1](https://github.com/geocoder-php/Geocoder/releases/tag/2.8.1).
Major version `2` will reach **end of life on December 2015**.
#### 3.x
As of January 2017, version [3.x](https://github.com/geocoder-php/Geocoder/tree/3.x)
is in a **feature frozen** state. All new features should be contributed to version 4.0
and upper. Last version is:
[3.3.2](https://github.com/geocoder-php/php-common/releases/tag/v3.3.2).
Major version `3` will reach **end of life on October 2017**.
### Stable Version
Version `4.x` is the current major stable version of Geocoder.
### Next version
There is no new major version planned at this time.
## Contributing
See [`CONTRIBUTING`](https://github.com/geocoder-php/Geocoder/blob/master/CONTRIBUTING.md#contributing) file.
## Unit Tests
In order to run the test suite, install the development dependencies:
```cmd
composer install --dev
```
Then, run the following command:
```cmd
composer test
```
You'll obtain some _skipped_ unit tests due to the need of API keys.
Rename the `phpunit.xml.dist` file to `phpunit.xml`, then uncomment the
following lines and add your own API keys:
```xml
```
You're done.
## Credits
* William Durand
* Tobias Nyholm
* [All contributors](https://github.com/geocoder-php/Geocoder/contributors)
## License
Geocoder is released under the MIT License. See the bundled LICENSE file for details.