I have a method wich should get a location and send it's result as a resolved Promise. However I have no idea how to await for the listener to finish or to workaround. It uses Google Services API to get current location.
// LocationModule.java
@ReactMethod
public void getLocation(String debugMessage, Promise promise) {
try {
this.fusedLocationClient.getLastLocation()
.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if(location != null) {
promise.resolve(location);
}
}
});
// promise.resolve(debugMessage); this would be called before the promise above and if it isn't present here app crashes
} catch(Exception e) {
promise.reject("Something went wrong", e);
}
}