1414use Geocoder \Dumper \Kml ;
1515use Geocoder \Dumper \Wkb ;
1616use Geocoder \Dumper \Wkt ;
17- use Geocoder \Geocoder ;
1817use Geocoder \Laravel \Exceptions \InvalidDumperException ;
1918use Geocoder \ProviderAggregator ;
2019use Geocoder \Query \GeocodeQuery ;
21- use Geocoder \Query \Query ;
2220use Geocoder \Query \ReverseQuery ;
2321use Illuminate \Support \Collection ;
22+ use Illuminate \Support \Str ;
2423use ReflectionClass ;
2524
2625/**
@@ -51,6 +50,13 @@ public function get() : Collection
5150 return $ this ->results ;
5251 }
5352
53+ public function toJson () : string
54+ {
55+ return $ this
56+ ->dump ("geojson " )
57+ ->first ();
58+ }
59+
5460 public function dump (string $ dumper ) : Collection
5561 {
5662 $ dumperClasses = collect ([
@@ -66,6 +72,7 @@ public function dump(string $dumper) : Collection
6672 "The dumper specified (' {$ dumper }') is invalid. Valid dumpers " ,
6773 "are: geojson, gpx, kml, wkb, wkt. " ,
6874 ]);
75+
6976 throw new InvalidDumperException ($ errorMessage );
7077 }
7178
@@ -80,7 +87,7 @@ public function dump(string $dumper) : Collection
8087
8188 public function geocode (string $ value ) : self
8289 {
83- $ cacheKey = str_slug (strtolower (urlencode ($ value )));
90+ $ cacheKey = ( new Str )-> slug (strtolower (urlencode ($ value )));
8491 $ this ->results = $ this ->cacheRequest ($ cacheKey , [$ value ], "geocode " );
8592
8693 return $ this ;
@@ -149,7 +156,7 @@ public function registerProvidersFromConfig(Collection $providers) : self
149156
150157 public function reverse (float $ latitude , float $ longitude ) : self
151158 {
152- $ cacheKey = str_slug (strtolower (urlencode ("{$ latitude }- {$ longitude }" )));
159+ $ cacheKey = ( new Str )-> slug (strtolower (urlencode ("{$ latitude }- {$ longitude }" )));
153160 $ this ->results = $ this ->cacheRequest ($ cacheKey , [$ latitude , $ longitude ], "reverse " );
154161
155162 return $ this ;
@@ -184,13 +191,15 @@ protected function cacheRequest(string $cacheKey, array $queryElements, string $
184191 "value " => collect ($ this ->aggregator ->{$ queryType }(...$ queryElements )),
185192 ];
186193 });
194+
187195 $ result = $ this ->preventCacheKeyHashCollision (
188196 $ result ,
189197 $ hashedCacheKey ,
190198 $ cacheKey ,
191199 $ queryElements ,
192200 $ queryType
193201 );
202+
194203 $ this ->removeEmptyCacheEntry ($ result , $ hashedCacheKey );
195204
196205 return $ result ;
0 commit comments