2
2
3
3
import android .location .Address ;
4
4
import android .util .Log ;
5
+
5
6
import androidx .annotation .Nullable ;
6
7
7
8
import com .baseflow .geocoding .utils .AddressMapper ;
8
9
import com .baseflow .geocoding .utils .LocaleConverter ;
9
10
11
+ import java .io .IOException ;
12
+ import java .util .List ;
13
+
10
14
import io .flutter .plugin .common .BinaryMessenger ;
11
15
import io .flutter .plugin .common .MethodCall ;
12
16
import io .flutter .plugin .common .MethodChannel ;
13
17
import io .flutter .plugin .common .MethodChannel .MethodCallHandler ;
14
18
import io .flutter .plugin .common .MethodChannel .Result ;
15
-
16
- import java .io .IOException ;
17
- import java .util .List ;
19
+ import io .flutter .plugin .common .StandardMethodCodec ;
18
20
19
21
/**
20
22
* Translates incoming Geocoding MethodCalls into well formed Java function calls for {@link
23
25
final class MethodCallHandlerImpl implements MethodCallHandler {
24
26
private static final String TAG = "MethodCallHandlerImpl" ;
25
27
private final Geocoding geocoding ;
26
- @ Nullable private MethodChannel channel ;
28
+ @ Nullable
29
+ private MethodChannel channel ;
27
30
28
- /** Forwards all incoming MethodChannel calls to the given {@code geocoding}. */
31
+ /**
32
+ * Forwards all incoming MethodChannel calls to the given {@code geocoding}.
33
+ */
29
34
MethodCallHandlerImpl (Geocoding geocoding ) {
30
35
this .geocoding = geocoding ;
31
36
}
32
37
33
38
@ Override
34
- public void onMethodCall (MethodCall call , Result result ) {
39
+ public void onMethodCall (final MethodCall call , final Result result ) {
35
40
switch (call .method ) {
36
41
case "locationFromAddress" :
37
42
onLocationFromAddress (call , result );
@@ -57,8 +62,8 @@ void startListening(BinaryMessenger messenger) {
57
62
Log .wtf (TAG , "Setting a method call handler before the last was disposed." );
58
63
stopListening ();
59
64
}
60
-
61
- channel = new MethodChannel (messenger , "flutter.baseflow.com/geocoding" );
65
+ final BinaryMessenger . TaskQueue taskQueue = messenger . makeBackgroundTaskQueue ();
66
+ channel = new MethodChannel (messenger , "flutter.baseflow.com/geocoding" , StandardMethodCodec . INSTANCE , taskQueue );
62
67
channel .setMethodCallHandler (this );
63
68
}
64
69
@@ -111,7 +116,7 @@ private void onLocationFromAddress(MethodCall call, Result result) {
111
116
}
112
117
}
113
118
114
- private void onPlacemarkFromCoordinates (MethodCall call , Result result ) {
119
+ private void onPlacemarkFromCoordinates (final MethodCall call , final Result result ) {
115
120
final double latitude = call .argument ("latitude" );
116
121
final double longitude = call .argument ("longitude" );
117
122
final String languageTag = call .argument ("localeIdentifier" );
@@ -121,15 +126,13 @@ private void onPlacemarkFromCoordinates(MethodCall call, Result result) {
121
126
latitude ,
122
127
longitude ,
123
128
LocaleConverter .fromLanguageTag (languageTag ));
124
-
125
129
if (addresses == null || addresses .isEmpty ()) {
126
130
result .error (
127
131
"NOT_FOUND" ,
128
132
String .format ("No address information found for supplied coordinates (latitude: %f, longitude: %f)." , latitude , longitude ),
129
133
null );
130
134
return ;
131
135
}
132
-
133
136
result .success (AddressMapper .toAddressHashMapList (addresses ));
134
137
} catch (IOException ex ) {
135
138
result .error (
0 commit comments