Geolocation In Webviewer Not Working

I do have the Location Sensor enabled (see screenshot), and still my app cannot detect location. The location permission dialogue doesn’t even pop up. It works great on web, and even mobile browsers on the same phone on which my Thunkable app is installed.

My app is 100% a webviewer app, built with PHP, so I didn’t use any Thunkable blocks in building it.

Please help!

@domhnallohanlon

Here’s a bit of the javascript I’m using:

var currentlat;
    var currentlng;
    navigator.geolocation.getCurrentPosition(callback, getError);

    function callback (position) {
        currentlat = position.coords.latitude;
        currentlng = position.coords.longitude;

        console.log("latitude: " + currentlat+"\nlongitude: "+ currentlng);
    }

    function getError(err){
        console.log(err);
        alert(err.message);
    }

And here’s what I get when I load that page from my webviewer app:

I tried to execute your code, but it didn’t work in the browser.

Check this

https://x.thunkable.com/projects/5e917bd8c6755a7316cc3a5e/project/properties/designer/

@actech

Please do it like this:

<script>
    // Create the script tag, set the appropriate attributes
    var currentlat;
    var currentlng;

    function getLocation() {
        navigator.geolocation.getCurrentPosition(callback, getError);

        function callback (position) {
            currentlat = position.coords.latitude;
            currentlng = position.coords.longitude;

            console.log("latitude: " + currentlat+"\nlongitude: "+ currentlng);
        }

        function getError(err){
            console.log(err);
            alert(err.message);
        }
    }

    getLocation();
</script>

This show “DataCloneError: The object could not be cloned.”. Check my example.

Thanks. I’ll check it out and get back to you.

I think your example might work, but to do this, you need to allow geolocation detection in your phone settings

Geolocation is allowed on this android phone I’m testing with, which is why when I load the app (it’s a web application built with Laravel) in my mobile browser, geolocation works fine.

But upon your suggestion, I’m going to install the app on a different android phone. I’ll let you know in a few minutes how it goes. Please stand by.

First, I recommend that you check my example and then use a different phone

@actech I really appreciate the quick response. Thank you!

I looked at your example and simply copy-pasted your js snippet into the relevant page on my page that needs the geolocation, button and all.

Currently installing the app in a different android phone. When it’s done, I’m going to click your button and let you know what I find.

@actech

Still investigating your suggestions.

In the meantime, I went to upload my apk into Google’s Console for an internal test track. They scanned my apk and if you look at this warning, you can clearly tell that LOCATION is not listed in the required permissions.

I’m positive that this means my downloaded Thunkable apk does not include location in the permissions list, even though I included Thunkable’s Location Sensor in my app. See screenshot.

Just thought I’d point that out and get your opinion on it. What

I don’t use Thunkable X to download projects from Google Play and for this reason I can’t say anything.

I gave you an example that works for me in browser view and in Live on Android 9 and 8.

No, that is not what I did. I UPLOADED my Thunkable apk into Google, so that my testing group could download that private release for internal testing purposes. Part of that process is Google scanning the APK to see what permissions it requires.

I was just pointing out that LOCATION should have been listed in that little report from Google, but it wasn’t. Could that be one of the reasons why I’m struggling with location?

PS: I tried your example in the app and got exactly the same results as before. Uploading to Google is just something else that I was trying out when I noticed that location was not listed, meaning the Thunkable APK is NOT including location services at all.

@actech

Let me clarify:

When I tested your code, I only took the javascript portion of your example (not the blocks), and pasted into my web app where geolocation is required. Just as before, it works great (gets the location) when viewed in a browser (even mobile browser on my phone), BUT NOT IN MY THUNKABLE WEBVIEWER APP.

This is the challenge.

@actech

I have updated my example and ask you to run my example in your Live on your Android device and tell me if it works or not. The geolocation data will disappear in about 2 seconds and you need to wait after clicking the button.

After clicking this button, what happens?

Sounds good. Installing Thunkable Live now. I’ll let you know how it goes. Please stand by.

I installed the apk on my phone and now I see your problem. Yes, it works in Live, but it doesn’t work in apk.

Thank you! What’s missing? Why is location services not working?

Unfortunately, I can’t give an answer to this question.

I understand, but Thunkable apps should be able to detect location, correct?

What should I do now?