I have the following code:
<!DOCTYPE html>
<html>
<body>
<p>Presiona el botón para obtener tus coordenadas.</p>
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocalización no es soportada por tu navegador.";
}
}
function showPosition(position) {
x.innerHTML = "Latitud: " + position.coords.latitude +
"<br>Longitud: " + position.coords.longitude;
}
</script>
</body>
</html>
How do I remove the button and have it automatically put the latitude and longitude in a text field?