รหัสที่ได้รับการปรับปรุง / มีประสิทธิภาพสำหรับหลาย ๆ if - React Native

////Central Location Service to get current location.
var currentLocation;
var locationType

if Android {
    DEFINED_ACCURACY = QUALITY_BALANCED_POWER
} else id iOS {
    DEFINED_ACCURACY = kCLLocationAccuracyHundredMeters
}


DEFINED_DISTANCE = 3000

function startLocationService(){
    var locationservice = LocationService()
    locationservcie.accuracy = DEFINED_ACCURACY
    locationservcie.distance = DEFINED_DISTANCE
    locationservcie.startListnertoLocationUpdate() {
        cacheData(location, currentTime);
        currentLocation = location
    }
}

function getLocationFromLocationService() {
    if locationServcieEnabled == false
        return NULL;
    if locationPermissionGranted == false
        return NULL;
    return currentLocation;
     
}
function getCurrentLocation() {
    var lcoation = NULL;
    var accuracy = Not_defined;


    lcoation = getLocationFromLocationService() //GPS, network
    locationType = locationService
    
    if lcoation == NULL {
        locationdata == getLastKnownLocation()
        if locationdata.Age < DEFINED_DURATION {
            location = locationdata.location
            locationType = locationService
        }
    }
    if location == NULL {
        location == getCachedLocationWithin24Hour()
        locationType = locationService
    }
    if location == NULL {
        location = getLocationfromTelephony()
        locationType = other
    }
    if location == NULL {
        if permissionToUseBilling == false {
            askForPermissionToUseBilling()
        }
        location = getLocationFromBillimg()
        accuracy = other
    }
    if location == NULL {
        location = getLocationOfDEfaultCountry()
        accuracy = other
    }
    return location, Other
}
   const location = getLocationFromLocationService() ;
   switch (location) {
   case 'NULL':
   //DO SOMETHING WHEN NULL;
   break;
   case 'New York':
   // DO SOMETHING WHEN New York;
   // No break leads to run also into the next case
   case 'Bern':
   console.log('I love nice cities.');
   break;
   default:
   console.log(`Sorry, we are out of ${location}.`);
}