How to Send Geolocation info to Server using PHP?

I am trying to access geolocation using javascript then send it to server using PHP.I am using,xmlhttp.send() as well as jQuery.ajax or $ .ajax function but none of them seemed to work. Should I create a tag to send location using GET ? My code is the following:

<!DOCTYPE html> <html><body> <h1>Click the following button to share your location!</h1><br> <button onclick="getLoc();">Share!</button> <script>     function getLoc()     {         navigator.geolocation.getCurrentPosition(success,error,option);     }     function success(pos)     {         var lat=pos.coords.latitude;         var lng=pos.coords.longitude;         $  .ajax({             type: "GET",              url:  "loc.php",              data:{ "q1" : "lat" },{ "q2" : "lng" },              cache: false         });     }     function error(err)     {         window.alert("Geolocation not supported!");     }     var option =      {         enableHighAccuracy: true,         timeout: 5000,         maximumAge: 0     }; </script> </body> </html> 

For PHP part, I did the following:

<!DOCTYPE html> <html> <body> <?php     $  fp=fopen("location.txt","a");     fputs($  fp,"Lat: ".$  _GET["q1"]." Lang: ".$  _GET["q2"]."\n");     fclose($  fp); ?> </body> </html> 

I have defined success() as following.

function success(pos) {"GET","loc.php?q1="+pos.coords.latitude+"&q2="+pos.coords.longitude,true);         xmlhttp.send(); } 

I also replaced xmlhttp with XMLHttpRequest. But none seemed to work. If I can do it with GET then I will try using POST.

How to pass a parameter allow= “geolocation” when embedding Google Apps Script in a Google site?

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="" 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')      .setSandboxMode(HtmlService.SandboxMode.IFRAME)      .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);} 

But this did not make a change.

Here now my code: :

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

html code (pmtest) :

<!DOCTYPE html> <html>  <script src=" is my  key....&libraries=places&callback=initMap"> </script>  <script> var myCenter=new google.maps.LatLng(51.158742,6.7170850);  function initialize() {  if (navigator.geolocation) {     navigator.geolocation.getCurrentPosition(function(position) {         alert('success');         var myLatlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);         alert('myLatlng : ' + myLatlng);         myCenter = myLatlng;         CenterMap();         marker.setPosition(myCenter);     }, function(error) {        alert('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}); marker.setMap(map); function CenterMap(){ map.panTo(myCenter);} }  google.maps.event.addDomListener(window, 'load', initialize); </script>  <body>  <div id="googleMap" style="width:1200px;height:700px;"></div> </body> </html> 

In case you want to open the test page, here is the link: 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.