@@ -230,41 +230,53 @@ Read more about cache [here](cache.md).
230230If you need to dump your geocoded data to a specific format, you can use the
231231__Dumper__ component. The following dumper's are supported :
232232
233- * Geojson
233+ * GeoArray
234+ * GeoJson
234235 * GPX
235- * KMP
236+ * KML
236237 * WKB
237238 * WKT
238239
239- Here is an example :
240+ Here is an example if you are using autowiring :
240241
241242` ` ` php
242243<?php
243244
244- public function geocodeAction(Request $request)
245+ namespace App\C ontroller;
246+
247+ use Geocoder\D umper\G eoJson;
248+ use Geocoder\P rovider\P rovider;
249+ use Geocoder\Q uery\G eocodeQuery;
250+ use Symfony\C omponent\H ttpFoundation\J sonResponse;
251+ use Symfony\C omponent\H ttpFoundation\R equest;
252+
253+ class AcmeController
245254{
246- $result = $this->container
247- ->get('bazinga_geocoder.provider.acme')
248- ->geocodeQuery(GeocodeQuery::create($request->server->get('REMOTE_ADDR')));
255+ private $acmeGeocoder;
256+ private $geoJsonDumper;
249257
250- $body = $this->container
251- ->get('Geocoder\D umper\G eoJson')
252- ->dump($result);
258+ public function __construct(Provider $acmeGeocoder, GeoJson $dumper)
259+ {
260+ $this->acmeGeocoder = $acmeGeocoder;
261+ $this->geoJsonDumper = $dumper;
262+ }
263+
264+ public function geocodeAction(Request $request)
265+ {
266+ $result = $this->acmeGeocoder->geocodeQuery(GeocodeQuery::create($request->server->get('REMOTE_ADDR')));
253267
254- $response = new Response();
255- $response->setContent($body);
268+ $body = $this->geoJsonDumper->dump($result);
256269
257- return $response;
270+ return new JsonResponse($body);
271+ }
258272}
259273` ` `
260274
261- To register a new dumper, you must tag it with `bazinga_geocoder.dumper`.
262-
263- ` ` ` xml
264- <service id="some.dumper" class="%some.dumper.class">
265- <tag name="bazinga_geocoder.dumper" alias="custom" />
266- </service>
267- ` ` `
275+ Each dumper service if it implements `Geocoder\Dumper\Dumper` interface will be
276+ tagged with `bazinga_geocoder.dumper` tag. Each dumper can be used with autowiring
277+ providing the dumper class name as the argument.
278+ Also If you want to inject all the tagged dumpers to your service you can provide
279+ your service argument as : ` !tagged bazinga_geocoder.dumper` .
268280
269281# ## Custom HTTP Client
270282
0 commit comments