GPS JS code only works in desktop browsers

Im trying to get the GPS location from any smartphone, Im using the same code provided by w3schools

While opening the w3school from my smartphone, it actually triggers the GPS functions and get the location with good accuracy, when I try to launch the code on my smartphone on any hype project, it wont work, it just does nothing.

Strangely, the same hype projects seems to work just fine when is launched from any desktop browser, but in smartphones, it just wont do anything.

testgps.hype.zip (749.7 KB)

It looks like they only thing you are missing here is setting a 'Unique Element ID' of the GPS DATA SHOULD APPEAR HERE object. You had two elements with the same ID:

testgps.hype.zip (86.9 KB)

When attempting to access geolocation over a local preview server (served from Hype) you'll get this error on Mobile Safari:

[blocked] Access to geolocation was blocked over insecure connection to http://127.0.0.1:52297

So if you upload your test document to a server that supports https and try it out, it should work.

1 Like

How strange, I just checked the attached file and there is no duplicates with the demo ID, and the textbox already have the demo ID.

Still, even your .hype file is failing on my smartphone test (android).

Do you have access to the developer console logging that might show an error?

Just this one:

But in desktop it shows the GPS coordinates, is only in smartphones where it fails to work.

I uploaded the site for live testing, and now I am getting a new error: A Geolocation request can only be fulfilled in a secure context.

As @Daniel said, seems to be a HTTPS related error, I will try to fix it on my side looks like there is nothing else to do, bummer.

@Daniel is right. GPS doesn’t work on preview, only when website is store in a https domain