I have a chain of async functions that must return true or false, but i get undefined from a function than gets location.
here is the function that returns undefined:
async getGeoLoc(trigger = 'cDidMount') {
return navigator.geolocation.getCurrentPosition(
async position => {
const isDataReady = await this.setCityFromCoordinate(
trigger,
position.coords.latitude,
position.coords.longitude,
);
console.log('isDataReady getGeoLoc', isDataReady); // this gives true in console
return isDataReady
},
i call it here:
async getLocationPermission(trigger) {
if (Platform.OS == 'android') {
const response = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
);
if (
response == PermissionsAndroid.RESULTS.DENIED ||
response == PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN
) {
Alert.alert(
i18n.t('search:geolocation_disabled'),
i18n.t('search:need_location'),
);
return false;
} else {
return await this.getGeoLoc(trigger);
}
} else {
return await this.getGeoLoc(trigger);
// for ios go directly here
}
},
THANKS!