Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
Grab user geolocation an pass it into contact form 7

I'm trying to set a certain form with WP CF7 and would like to grab the exact user geolocation and pass it into the mail sent to the admin, something like this;

<!DOCTYPE html>
<html>
<body>

<p>Click the button to get your coordinates.</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 = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude;
}
</script>

</body>
</html>

only instead of printing lon and lat results -> pass it in mail, perhaps using cookies? (store it and then read it?)

I appreciate any help, Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should use navigator.watchPosition so you don't have a popup in the Browser again. Do like:

let lat, lng;
navigator.watchPosition(position=>{
  const pos = position.coords;
  const undef = lat === undefined;
  lat = pos.latitude; lng = pos.longitude;
  if(undef){
    latElement.value = lat; lngElement.value = lng;
  }
}, error=>{
  throw new Error(error.message);
}, {enableHighAccuracy:true});
someLatLngUpdateButton.onclick = ()=>{
  latElement.value = lat; lngElement.value = lng;
}

Of course, this design would assign lat and lng only if they haven't been, then update them when you hit a button. You could constantly update the Elements, but that might be annoying.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda