@@ -237,41 +237,53 @@ Read more about cache [here](cache.md).
237237If you need to dump your geocoded data to a specific format, you can use the
238238__Dumper__ component. The following dumper's are supported :
239239
240- * Geojson
240+ * GeoArray
241+ * GeoJson
241242 * GPX
242- * KMP
243+ * KML
243244 * WKB
244245 * WKT
245246
246- Here is an example :
247+ Here is an example if you are using autowiring :
247248
248249` ` ` php
249250<?php
250251
251- public function geocodeAction(Request $request)
252+ namespace App\C ontroller;
253+
254+ use Geocoder\D umper\G eoJson;
255+ use Geocoder\P rovider\P rovider;
256+ use Geocoder\Q uery\G eocodeQuery;
257+ use Symfony\C omponent\H ttpFoundation\J sonResponse;
258+ use Symfony\C omponent\H ttpFoundation\R equest;
259+
260+ class AcmeController
252261{
253- $result = $this->container
254- ->get('bazinga_geocoder.provider.acme')
255- ->geocodeQuery(GeocodeQuery::create($request->server->get('REMOTE_ADDR')));
262+ private $acmeGeocoder;
263+ private $geoJsonDumper;
256264
257- $body = $this->container
258- ->get('Geocoder\D umper\G eoJson')
259- ->dump($result);
265+ public function __construct(Provider $acmeGeocoder, GeoJson $dumper)
266+ {
267+ $this->acmeGeocoder = $acmeGeocoder;
268+ $this->geoJsonDumper = $dumper;
269+ }
270+
271+ public function geocodeAction(Request $request)
272+ {
273+ $result = $this->acmeGeocoder->geocodeQuery(GeocodeQuery::create($request->server->get('REMOTE_ADDR')));
260274
261- $response = new Response();
262- $response->setContent($body);
275+ $body = $this->geoJsonDumper->dump($result);
263276
264- return $response;
277+ return new JsonResponse($body);
278+ }
265279}
266280` ` `
267281
268- To register a new dumper, you must tag it with `bazinga_geocoder.dumper`.
269-
270- ` ` ` xml
271- <service id="some.dumper" class="%some.dumper.class">
272- <tag name="bazinga_geocoder.dumper" alias="custom" />
273- </service>
274- ` ` `
282+ Each dumper service if it implements `Geocoder\Dumper\Dumper` interface will be
283+ tagged with `bazinga_geocoder.dumper` tag. Each dumper can be used with autowiring
284+ providing the dumper class name as the argument.
285+ Also If you want to inject all the tagged dumpers to your service you can provide
286+ your service argument as : ` !tagged bazinga_geocoder.dumper` .
275287
276288# ## Custom HTTP Client
277289
0 commit comments