Distance cannot be determined when mobile device location information is turned off

Hello bubbler.
I am experiencing a strange phenomenon regarding current geographic position when using Android, and I need your wisdom.

My app is designed to determine the distance between the user’s current geographic position and the target facility.
If the distance is 0.1 km or more from the target facility, the app will give a NO answer, and if it is closer, it will give a YES answer.
The user must allow GPS position on his/her device.

It works fine on almost all mobile devices.
However, with certain models, if the device’s GPS setting is turned off, a YES decision will be given even if the device is more than 0.1 km away from the target facility.

The handsets with confirmed symptoms are
Xperia Ace SO-02L
Android 10.
chrome browser

Does anyone know of similar symptoms or know how to deal with them?
If it is the Xperia’s fault, I give up.

You could run javascript on page load to determine if they allow access to their location and if they do then proceed but if they do not then return them to a login page or error page.

function geolocFail(){
    let errorMessage = 'Please check your browser settings to enable tracking.' 
    console.log(errorMessage)
    window.location.replace("https://www.myexampleerrorpage.com")
}

if (navigator.geolocation) {
    
    navigator.geolocation.getCurrentPosition(function(position) {
        console.log("access")
    }, function(error) {
        geolocFail();
    });
} else {
    // Fallback for no geolocation
    geolocFail();
}
2 Likes

Thank you for your reply.
Sorry for the delay in replying.

I am currently using workflow to control the determination, but it looks like javascript would allow me to limit it at the loading stage.
I don’t know why only Xperia slips through the GPS determination, but your code is definitely what I wanted.

Thank you so much!!!

1 Like