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

223
Vistas
I want to pull data from the Weather api but getting some errors

I am getting these errors:

  1. GET http://127.0.0.1:5500/src/api.openweathermap.org/data/2.5/weather?lat=29.0188653&lon=77.7680952&appid=9268356eb17fbbe77a86201da74c9c46 404 (Not Found)
  2. Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 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 Respuestas
Responde la pregunta

0

Try adding https:// to the URL like so

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

about 4 years ago · Juan Pablo Isaza Denunciar

0

Your local dev environment should be secure, i.e., you need to use https://localhost or https://127.0.0.1 to retrieve the lat and lnt data of your user, in this case, yourself's.

Use this to setup create a https certificate on your local machine, https://github.com/FiloSottile/mkcert

Besides, you need this link as a guide, https://www.section.io/engineering-education/how-to-get-ssl-https-for-localhost/

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

navigator.geolocation.getCurrentPosition should be in a secure environment, even if it's localhost.

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