8
8
import android .os .Build ;
9
9
import android .text .TextUtils ;
10
10
import android .provider .Settings ;
11
+
12
+ import androidx .annotation .Nullable ;
11
13
import androidx .core .app .ActivityCompat ;
12
14
13
15
import com .facebook .react .bridge .Arguments ;
@@ -78,14 +80,17 @@ public static boolean isProviderEnabled(Context context, String provider) {
78
80
/**
79
81
* Build error response for error callback.
80
82
*/
81
- public static WritableMap buildError (int code , String message ) {
82
- WritableMap error = Arguments .createMap ();
83
- error .putInt ("code" , code );
83
+ public static WritableMap buildError (LocationError locationError , @ Nullable String message ) {
84
+ String msg = message ;
84
85
85
- if (message ! = null ) {
86
- error . putString ( "message" , message );
86
+ if (msg = = null ) {
87
+ msg = getDefaultErrorMessage ( locationError );
87
88
}
88
89
90
+ WritableMap error = Arguments .createMap ();
91
+ error .putInt ("code" , locationError .getValue ());
92
+ error .putString ("message" , msg );
93
+
89
94
return error ;
90
95
}
91
96
@@ -108,4 +113,22 @@ public static WritableMap locationToMap(Location location) {
108
113
109
114
return map ;
110
115
}
116
+
117
+ private static String getDefaultErrorMessage (LocationError locationError ) {
118
+ switch (locationError ) {
119
+ case PERMISSION_DENIED :
120
+ return "Location permission not granted." ;
121
+ case POSITION_UNAVAILABLE :
122
+ return "No location provider available." ;
123
+ case TIMEOUT :
124
+ return "Location request timed out." ;
125
+ case PLAY_SERVICE_NOT_AVAILABLE :
126
+ return "Google play service is not available." ;
127
+ case SETTINGS_NOT_SATISFIED :
128
+ return "Location settings are not satisfied." ;
129
+ case INTERNAL_ERROR :
130
+ default :
131
+ return "Internal error occurred" ;
132
+ }
133
+ }
111
134
}
0 commit comments