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

154
Vistas
I want to grab the data from a function and pass it into a fetch URL, to get city data

This is the code that I am working on below. I am trying to grab the latitude and longitude data from the 1st url, so that I can pass that into a new fetch request that takes lat and lon to grab weather data on a city with a 5 day forecast. But I am unsure how to call the data from one function and pass it as a string in the URL.

let weather = {
    "apiKey": "",
    "city": " ",

    fetchWeather: function(city) {
        // this fetch will call the api to grab the Lon and lat, using the function displayLatlon
        fetch("https://api.openweathermap.org/data/2.5/weather?q=" + city 
        + "&units=imperial&appid=" 
        + this.apiKey)

        .then(response => response.json())
        .then(data => this.displaylatlon(data))
        // This fetch will use the API to grab the weather conditions for the city based on it's lat and lon
        fetch("https://api.openweathermap.org/data/3.0/onecall?lat=" + **lat**
        + "&lon=" + **lon** 
        + "&exclude=hourly,daily&appid=" 
        + this.apiKey)

        .then(response => response.json())
        .then(weatherData =>console.log(weatherData))

    },
    // Function to grab the latitude and longitude of the city
     **displaylatlon: function(data) {
        const {lat, lon} = data.coord
        const{temp} = data.main**
        
        console.log(lat, lon)
     }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Roughly:

fetch("https://api.openweathermap.org/data/2.5/weather?q=" + city 
        + "&units=imperial&appid=" 
        + this.apiKey)
.then(response => response.json())
.then(data => {
   const {lat, lon} = data.coord;
   return fetch("https://api.openweathermap.org/data/3.0/onecall?lat=" + **lat**
        + "&lon=" + **lon** 
        + "&exclude=hourly,daily&appid=" 
        + this.apiKey)
})
.then(response => response.json())
.then(weatherData =>console.log(weatherData))

You can open a {} scope to use multiple lines of code.

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