Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Tome la geolocalización del usuario y pásela al formulario de contacto 7

Estoy tratando de configurar un formulario determinado con WP CF7 y me gustaría tomar la geolocalización exacta del usuario y pasarla al correo enviado al administrador, algo como esto;

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

solo en lugar de imprimir los resultados de longitud y latitud -> pasarlo por correo, ¿quizás usando cookies? (¿almacenarlo y luego leerlo?)

Agradezco cualquier ayuda, gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe usar navigator.watchPosition para que no vuelva a aparecer una ventana emergente en el navegador. Gustar:

 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; }

Por supuesto, este diseño asignaría lat y lng solo si no lo han sido, luego los actualizaría cuando presione un botón. Podría actualizar constantemente los Elementos, pero eso podría ser molesto.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!