Skip to content

Commit 58a0362

Browse files
committed
Android: rewrite location module using new location manager interface
1 parent 50e5082 commit 58a0362

File tree

2 files changed

+76
-471
lines changed

2 files changed

+76
-471
lines changed

android/src/main/java/com/agontuk/RNFusedLocation/LocationUtils.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import android.os.Build;
99
import android.text.TextUtils;
1010
import android.provider.Settings;
11+
12+
import androidx.annotation.Nullable;
1113
import androidx.core.app.ActivityCompat;
1214

1315
import com.facebook.react.bridge.Arguments;
@@ -78,14 +80,17 @@ public static boolean isProviderEnabled(Context context, String provider) {
7880
/**
7981
* Build error response for error callback.
8082
*/
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;
8485

85-
if (message != null) {
86-
error.putString("message", message);
86+
if (msg == null) {
87+
msg = getDefaultErrorMessage(locationError);
8788
}
8889

90+
WritableMap error = Arguments.createMap();
91+
error.putInt("code", locationError.getValue());
92+
error.putString("message", msg);
93+
8994
return error;
9095
}
9196

@@ -108,4 +113,22 @@ public static WritableMap locationToMap(Location location) {
108113

109114
return map;
110115
}
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+
}
111134
}

0 commit comments

Comments
 (0)