Please how to I enable GPS inside an Iframe

This is my code but it does not enable GPS in wix Iframe

getLocation()    
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    window.alert("Geolocation is not supported by this browser.");
  }
}

function showPosition(position) {
  window.x= []
  window.x.push(position.coords.latitude)
  window.x.push(position.coords.longitude);

}     

I tried your code in Wix iframe, and it worked perfectly on my iPhone.
first time it asked for permission to access location and when I approved it, it showed the coordinates (I’ve added a few lines to show the results).

By the way, if you want to look for error, do something like:

navigator.geolocation.getCurrentPosition(showPosition, err => console.warn(`ERROR(${err.code}): ${err.message}`));

@jonatandor35 Did you have to add any custom code?

@jonatandor35 Did you add any src to the script tag?


<!DOCTYPE html>
<html>
<head>
    <title>GPS</title>
    <script type="text/javascript" src=" https://cdnjs.cloudflare.com/ajax/libs/webcamjs/1.0.25/webcam.js "></script>
   <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
    </script>


    <style>
     
    </style>
</head>
<body>
  
</body>
<script>

getLocation()    
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    window.alert("Geolocation is not supported by this browser.");
  }
}

function showPosition(position) {
  window.x= []
  window.x.push(position.coords.latitude)
  window.x.push(position.coords.longitude);
console.log("THE X IS", window.x)
//////////////////////////////////
        

}  


</script>
</html>


This is the entire code. works on a a html page but does not work in Wix html component

You should put the script between the tags.
I tested your code and found out that it works on sites connected to your own domain and does not work if it is under the wixsite.com generic domain.

@jonatandor35 I don’t understand your second point, my site is Premium

@chidiejike is it premium and already connected to your own domain?
If it is, I don’t know what the problem is. I tried your code and it worked on my iphone.

See screenshot.
I used window.alert(window.x[0]); on my iphone and you can see the coords.

@jonatandor35 Please have you tried it on desktop?, My Premium account is on Wix. Is there any other domain name that is not owned by the Admin? I don’t understand. I own the domain name hosted in Wix.