Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
I'm having problems with the OpenWeather API + geolocation

This is my first time working with an API. It will be part of a bigger practice project, but I'm a bit stuck. First, I want my code to geolocate the user, get the altitude and longitude, than using that make a call to the OpenWeather API and console log the temperature, humidity and the description. My problem seems to be that my link is not working... can anyone help me explain what am I doing wrong? (The Api key is deleted here)

 /*Geolocation*/

let latUser = []
let lonUser = []


const errorCallback = (error) => {console.error(error)}
const successCallback = (position) => {
    latUser.push(position.coords.latitude)
    lonUser.push(position.coords.longitude)}

navigator.geolocation.getCurrentPosition(successCallback, errorCallback) 

/*Weather*/

let weather = {
    "apiKey": "xxx",
    fetchWeather: function () {
        fetch("api.openweathermap.org/data/2.5/weather?lat=" + latUser[0] + "&lon=" + lonUser[0] +
         "&appid=" + this.apiKey
        ).then((response) => response.json())
        .then((data) => this.displayWeather(data))
    },
    displayWeather: function(data){
        const { temp, humidity } = data.main
        const { description } = data.weather
        console.log (temp, humidity, description)
    }
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda