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

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