The target is to embed a Google Apps Script gadget into my Google site. The function of this script is to show a google map, determin the location of the client and center the map to the found location.

The relevant command for getting the position is navigator.geolocation.getCurrentPosition.

The issue is that the security layers block the execution of this command when used with Chrome. (It works in Firefox and Safari. Also when I use "test web for your lates code", it works as intended).

enter image description here

Debugging the browser reveals the following error message: "Geolocation access has been blocked because of a Feature Policy applied to the current document. See (here comes a link) for more detail."

Following the explanations in the offered link, it results in the suggestion to apply a instruction for geolocation in the iframe command like:

<iframe src="https://example.com" allow="geolocation"></iframe>

Now here comes my problem: Since I can only use the functions in the Google Site editor to embed a GAS gadget, I have no option to modify an iframe instruction with such a parameter. Therefore, I do not know how I can pass this parameter into the web site.

The question is: Is there a method at all? If yes, what is the correct way to do it?

I have investigated a lot and also tried to add parameters to the doGet function in the sense of:

function doGet() { 
   return HtmlService.createHtmlOutputFromFile('pmtest') 

But this did not make a change.

Here now my code: code.gs :

function doGet() { return HtmlService.createHtmlOutputFromFile('pmtest') }

html code (pmtest) :

<!DOCTYPE html>

src="https://maps.googleapis.com/maps/api/js?key=...here is my 

var myCenter=new google.maps.LatLng(51.158742,6.7170850);

function initialize()

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
        var myLatlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
        alert('myLatlng : ' + myLatlng);
        myCenter = myLatlng;
    }, function(error) {

var mapProp = {
center: myCenter, zoom:18, gestureHandling: 'greedy', tilt: 0, draggableCursor: 'default',
mapTypeId: google.maps.MapTypeId.SATELLITE

var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
var marker = new google.maps.Marker({ position: myCenter});
function CenterMap(){ map.panTo(myCenter);}

google.maps.event.addDomListener(window, 'load', initialize);

 <div id="googleMap" style="width:1200px;height:700px;"></div>

In case you want to open the test page, here is the link: https://sites.google.com/site/pmtest4711/ When the geolocation command could be executed, a message will appear with "success" and a second with the found position. The google map then shows this location (wherever you are.).

Any good hint would be appreciated.

  • Welcome. Google Sites has a lot of restrictions, I'm not sure that this is possible. Have you find another Google Site that use this feature? – Rubén Dec 20 '18 at 18:53
  • Have you found any workaround at all? I would love to be able to do very nearly the same thing. – Jé Queue Apr 13 '19 at 21:14
  • Dear Je Queue, ...unfortunately I have not found any workaround yet. It seems we have to live with this restrictions and some things are just not possible with Google Sites. – Peter Mattheisen Apr 15 '19 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.