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

102
Views
Estoy tratando de crear una aplicación web móvil que muestre la ubicación, pero no funciona.

Soy nuevo en el desbordamiento de pila, me registré porque me encontré con un error. ¡Esto es para mi próximo proyecto de secundaria!

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <html> <body> <form> <input type="button" value="Result" onclick="getGeolocation" /> <input type="button" value="Result" onclick="getUserCoodinates" /> </form> <script type="text/javascript"> // <![CDATA[ //run this code when the page loads jQuery(document).ready(function() { getGeolocation(); }); //determine if the user's browser has location services enabled. If not, show a message function getGeolocation() { if (navigator.geolocation) { //if location services are turned on, continue and call the getUserCoordinates function below navigator.geolocation.getCurrentPosition(getUserCoodinates); } else { alert('You must enable your device\'s location services in order to run this application.'); } } //function is passed a position object which contains the lat and long value function getUserCoodinates(position) { //set the application's text inputs LAT and LONG = to the user's lat and long position jQuery("#LAT").val(position.coords.latitude); jQuery("#LONG").val(position.coords.longitude); } </script> </body> </html>

¿Dónde me he equivocado? ? ?

Estoy tratando de usar esto para una aplicación web móvil.

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

0

En su código, getUserCoodinates es una función de devolución de llamada, por lo que no debe invocarse directamente haciendo clic en un botón para que se pueda eliminar esa parte del HTML. Según el comentario de @Darkbee: el servidor web debería ejecutar la página a través de SSL/https; de lo contrario, esto fallará.

El segundo argumento que puede proporcionar a getCurrentPosition es para errores de procesamiento; parece tener sentido aquí usarlo para tratar de identificar el problema. Lo siguiente funciona perfectamente en mi sistema de prueba que ejecuta ssl con un certificado self-signed .

 document.querySelector('[type="button"]').addEventListener('click',(e)=>{ if( navigator.geolocation ){ const getUserCoodinates=(pos)=>{ $('#LAT').val(pos.coords.latitude); $('#LONG').val(pos.coords.longitude); }; const showError=(error)=>{ let msg='An unknown error occurred.'; switch( error.code ) { case error.PERMISSION_DENIED: msg='User denied the request for Geolocation.' break; case error.POSITION_UNAVAILABLE: msg='Location information is unavailable.' break; case error.TIMEOUT: msg='The request to get user location timed out.' break; default:break; } alert(msg); }; navigator.geolocation.getCurrentPosition(getUserCoodinates,showError); } });
 <script src='//cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script> <form> <input id='LAT' /> <input id='LONG' /> <input type='button' value='Result' /> </form>

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!