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

228
Views
Quiero extraer datos de la API de Weather, pero obtengo algunos errores.

Estoy recibiendo estos errores:

  1. OBTENGA http://127.0.0.1:5500/src/api.openweathermap.org/data/2.5/weather?lat=29.0188653&lon=77.7680952&appid=9268356eb17fbbe77a86201da74c9c46 404 (No encontrado)
  2. No capturado (en promesa) SyntaxError: token inesperado < en JSON en la posición 0

JavaScript

 window.addEventListener("load", () => { let lon; let lat; if (navigator.geolocation) { navigator.geolocation.getCurrentPosition((postion) => { lat = postion.coords.latitude; lon = postion.coords.longitude; const api = `api.openweathermap.org/data/2.5/weather? lat=${lat}&lon=${lon}&appid=9268356eb17fbbe77a86201da74c9c46`; fetch(api) .then((response) => { return response.json(); }) .then((data) => { console.log(data);a }) .catch((err) => alert("Enable your location")); }); // else{ // alert("Geolocation is not supported by this browser.";); // } } });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Intenta agregar https:// a la URL así

 const api = `https://api.openweathermap.org/data/2.5/weather? lat=${lat}&lon=${lon}&appid=9268356eb17fbbe77a86201da74c9c46`;

about 4 years ago · Juan Pablo Isaza Report

0

Su entorno de desarrollo local debe ser seguro, es decir, necesita usar https://localhost o https://127.0.0.1 para recuperar los datos de lat e lnt de su usuario, en este caso, los suyos.

Use esto para configurar la creación de un certificado https en su máquina local, https://github.com/FiloSottile/mkcert

Además, necesita este enlace como guía, https://www.section.io/engineering-education/how-to-get-ssl-https-for-localhost/

Referencia: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition

navigator.geolocation.getCurrentPosition debe estar en un entorno seguro, incluso si es localhost.

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!