输入字段和表单提交的地理定位(google 脚本)

Geolocation to imput field and form submition (google script)

您好,我有这个 link 可以通过 GPS 获取当前用户位置。它是我从不同地方获取不同代码的表单脚本的一部分。

当按下按钮时,它会显示一个带有坐标的段落。

<button onclick="getLocation()">Obtener coordenadas de GPS del movil</button>

<p id="demo"></p>

<script>
var x = document.getElementById("demo");

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

function showPosition(position) {
x.innerHTML = position.coords.latitude + "," + position.coords.longitude;
}

</script>

但我想以以下形式填充此字段:

<div id="formDiv">
<!-- Form div will be hidden after form submission -->
<form id="myForm">
<br/>
Ubicacion: <input name="ubicacion" type="text" size="64" /><br/>

有人知道这是否可行吗?尝试了几件事,但 none 工作,直到我不太了解 javascript.

这是表格:site

在按下 "obtener coordenadas del GPS" 时,它应该填充 "Ubicacion" 输入字段。

知道了!我应该使用另一个公式:.value 而不是 .innerHTML

 <button onclick="getLocation()">Obtener coordenadas de GPS del movil</button><br/>
<script>
 function getLocation() {
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
} else { 
    document.getElementById("ub").value = "Geolocation is not supported by this browser.";
       }
}
function showPosition(position) {
document.getElementById("ub").value = 
     position.coords.latitude + "," +   position.coords.longitude;
}
</script>

似乎也使用 var x = 不起作用

 Ubicacion: <input name="ubicacion" type="text" size="64" /><br/>