Question

In: Computer Science

I want to know how to get the "temp" information from a API response like this...

I want to know how to get the "temp" information from a API response like this in javascript:

{
  "coord": {
    "lon": -122.08,
    "lat": 37.39
  },
  "weather": [
    {
      "id": 800,
      "main": "Clear",
      "description": "clear sky",
      "icon": "01d"
    }
  ],
  "base": "stations",
  "main": {
    "temp": 282.55,
    "feels_like": 281.86,
    "temp_min": 280.37,
    "temp_max": 284.26,
    "pressure": 1023,
    "humidity": 100
  },
  "visibility": 16093,
  "wind": {
    "speed": 1.5,
    "deg": 350
  },
  "clouds": {
    "all": 1
  },
  "dt": 1560350645,
  "sys": {
    "type": 1,
    "id": 5122,
    "message": 0.0139,
    "country": "US",
    "sunrise": 1560343627,
    "sunset": 1560396563
  },
  "timezone": -25200,
  "id": 420006353,
  "name": "Mountain View",
  "cod": 200
  }                         

let Temperature = undefined;

let Wind = undefined;

let Humid = undefined;

let Visibility = undefined;

let weatherInfo = undefined;

I've written those things in my js work and I want to get temp, wind speed, humid and visibility in the api response.:

function getWeatherInfo (latitude, longitude) {

weatherInfo = "api.openweathermap.org/data/2.5/weather?lat="+latitude+"&lon="+longitude+"&appid={API key}";

return weatherInfo;

}

is my API right?

Solutions

Expert Solution

const fetch = require('node-fetch');
/////////////////////////////////////////////////////////////////
let lat = 37.39;
let lon = -122.08;
let key = "bff2d6d58917bc7f9587c06c3e5fc63e"

async function getapi(lat, lon, key) {
    const url = `https://api.openweathermap.org/data/2.5/weather?lat=${String(lat)}&lon=${String(lon)}&appid=${String(key)}`;
    const response = await fetch(url);
    return await response.json();
}

(async () => {

    const arr = await getapi(lat, lon, key);
    console.log(arr);
    console.log("Temperature is ", arr.main.temp);
    console.log("Pressure is ", arr.main.pressure);
    console.log("Humidity is ", arr.main.humidity);
    console.log("Visibility is ", arr.visibility);
    console.log("Wind is is ", arr.wind.speed);
    console.log("Weather description is ", arr.weather[0].description)

})()

IF YOU HAVE ANY DOUBT THEN JUST LEAVE A COMMENT AND I WILL CONNECT WITH YOU AS SOON AS POSSIBLE


Related Solutions

i want to create a weather api. which is pullling out information of all the cities(for...
i want to create a weather api. which is pullling out information of all the cities(for the whole world)  using their names or by their zipcode. and it should change the background image as the temperature is, cold, or hot, or mild etc. i need in help in making this weather api and also it can be in any language. please help me out
I know the what the answers are but I don't know how to get them. Can...
I know the what the answers are but I don't know how to get them. Can you please explain the process? Thank you. Part VII. Discontinued Operations and Earnings per Share (11 points) Todd Corporation had pre-tax income for 2017 of $2,500,000. On December 31, 2017, Boyd disposed of a component of its business that represented a strategic shift in operation. That component had a Loss on Discontinued Operations of $450,000 (pre-tax). Boyd received $1,000,000 net cash proceeds from the...
I would like to get som survey question for dry cleaning service , I want to...
I would like to get som survey question for dry cleaning service , I want to attract new people who live in the area like new homewoners.
This is my code I want the average temp for the week to be printed when...
This is my code I want the average temp for the week to be printed when the user types : 'week' currently when the user types  'week' it only prints  Monday - Sunday and the average temp for each day. import java.util.Arrays; import java.util.ArrayList; import java.util.Scanner; public class weeklytemps {    public static void main(String[] args) {        Scanner input = new Scanner(System.in);                  ArrayList Day = new ArrayList(Arrays.asList(    "Monday","Tuesday","Wednesday","Thurday","Friday","Saturday","Sunday")); // Stores days of the week...
I want to know everything there is to know about wireless networking, in particular, how to...
I want to know everything there is to know about wireless networking, in particular, how to connect a device to 5G cellular networks, also looking at NFC, GPS, all that would be helpful too
I marked the correct answers to these questions, but I just want to know how to...
I marked the correct answers to these questions, but I just want to know how to solve them. 1) In a cross of AaBbCcDdEeFf X AaBbccDdEeFf, what proportion will have the ABCDeF phenotype? A. 27/64 B. 27/128 C. 27/512 D. 81/512 E. 81/2048 #### 2.) In a cross of two flies +/vg Cy/+ +/se +/ab X +/vg +/+ se/se ab/ab what proportion of the offspring will be mutant in phenotype for all four markers? A. 0 B. 3/64 C. 1/16...
I want to know why I can not get N(should contain 1000 number) N<-vector() for (k...
I want to know why I can not get N(should contain 1000 number) N<-vector() for (k in 0:999){ y=vector() for(i in 0:999){ r1=runif(1) r2=runif(1) x1=-log(r1) x2=-log(r2) k=(x1-1)^2/2 if (x2 >= k){ r<-runif(1) if (r>0.5){ y[i]= x1 }else{ y[i]= -x1 } } y.1<- y[-which(is.na(y))] number<-length(y.1) } N[k]<-number } N
I already have the code of this program, I just want to know how to fix...
I already have the code of this program, I just want to know how to fix the code to Implement the 5th function (System.nanotime() and System.currentTimeMillis() methods) What Code does: Introduction Searching is a fundamental operation of computer applications and can be performed using either the inefficient linear search algorithm with a time complexity of O (n) or by using the more efficient binary search algorithm with a time complexity of O (log n). Task Requirements In this lab, you...
how do we use dictionaries to get json api in MIT app inventor
how do we use dictionaries to get json api in MIT app inventor
I want to know how long basketball shoes last for people on average. I rubbed a...
I want to know how long basketball shoes last for people on average. I rubbed a dusty coffee pot and a genie popped out to tell me that the standard deviation for the lifespan of all basketball shoes is 4.2 months. I polled 1225 people at the PEIF (before it closed) on how long their shoes lasted, and I got an average of 27 months. (a) What is the 95% confidence interval for the population mean lifespan of a basketball...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT