2017-01-20 1 views
0

안녕하세요. GPS로 현재 사용자 위치를 얻으려면이 링크가 필요합니다. 양식 스크립트의 일부는 다른 장소에서 다른 코드를 가져 왔습니다.입력란 및 양식 제출물 (Google 스크립트)에 대한 위치 정보

버튼을 누르면 좌표가있는 단락이 표시됩니다.

<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/> 

누구 아는 사람? tryed 여러 가지,하지만 아무도 작동하지 않을 때까지, 나는 자바 스크립트를 많이 알지 못한다. 그것은 "Ubicacion"imput 필드를 작성해야합니다 "GPS obtener coordenadas 델"압박 site

:

는 형태입니다.

답변

0

알 수 있습니다. .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/> 
를 사용하는 것 같습니다 : 나는 다른 공식을 사용해야