Hello,
I have a problem to access for the user geolocation inside the iframe and I guessed that the problems is because the iframe have a sandbox and don’t have allow=“geolocation”.
I made a custom component in ReactJS with Mapbox and many code in JS that requires geolocation because I need for my app a location of users.
// Without iframe inside Glide works fine.
https://www.app.roundroute.es/mapview?latitude=28.14336395263672&longitude=-15.65500259399414
To get user geolocation i’m using:
navigator.geolocation.getCurrentPosition
navigator.geolocation.watchPosition
getRegion = () => this.region;
getCurrentPosition = async () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
if (position &&
position.coords &&
position.coords.latitude &&
position.coords.longitude) {
this.setRegion(position.coords);
}
}, this.positionError, options);
}
else {
console.log(‘getCurrentPosition.navigation.undefined_geolocation’, navigator);
}
return this.region;
}
watchPosition = () => {
if (navigator.geolocation) {
this.trackId = navigator.geolocation.watchPosition(position => {
if (position &&
position.coords &&
position.coords.latitude &&
position.coords.longitude) {
this.setRegion(position.coords);
}
}, this.positionError, options);
}
else {
console.log(‘getCurrentPosition.navigation.undefined_geolocation’, navigator);
}
}
clearWatch = () => {
if (navigator.geolocation && this.trackId !== null) {
navigator.geolocation.clearWatch(this.trackId);
}
}
positionError = (error) => {
switch (error.code) {
case error.PERMISSION_DENIED:
this.setError(“Error: Permisos GPS rechazados.”);
break;
case error.POSITION_UNAVAILABLE:
this.setError(“Error: Información de la localización no disponible.”);
break;
case error.TIMEOUT:
this.setError(“Error: Tiempo de espera para acceder a la ubicación elevado.”);
break;
case error.UNKNOWN_ERROR:
this.setError(“Error: Error con el GPS desconocido.”);
break;
default:
this.setError(error.message);
break;
}
}
The methods are rejected always with ERROR.PERMISSION_DENIED and the browser have enabled the GPS, I checked the permissions from the page with the chrome console:
// Works great
navigator.geolocation.getCurrentPosition(position => console.log(position));
I made a new view with the iframe and location component and I have a retry each 5 seconds and when the location are enabled and the permissions accepted are rejected yet.
Thanks.