Skip to content

Calling the Open Weather Map API

How to start – OpenWeatherMap

Tips on how to use API effectively 1 We recommend making calls to the API no more than one time every 10 minutes for one location (city / coordinates / zip-code). This is due to the fact that weather data in our system is updated no more than one time every 10 minutes.

Weather API · Sign Up · City

Weather API – OpenWeatherMap

Weather maps 1.0 API doc Subscribe. Weather maps include precipitation, clouds, pressure, temperature, wind, and more; Connect our weather maps to your mobile applications and websites; Use as layers in Direct Tiles, OpenLayers, Leaflet, and Google Maps…

API Key · Current · Sign In · Price · Carbon Monoxide Data (Co) · 5 Day Weather Forecast

How to Use jQuery Post Method to Call OpenWeatherMap API

I chose the OpenWeatherMap API to illustrate the codes to you. To tell you more about the OpenWeatherMapAPI – It is a very popular and a free weather API, that provides weather information for all the cities on earth. Background. Before making the API call, you should create your free account at OpenWeatherMap and get your API Key. You will

OpenWeatherMap API | ProgrammableWeb

The Open Weather Map API allows users to retrieve the current weather at a city or weather station, the historical measurements for a weather station, or a list of cities and/or weather stations in a given rectangle (limited by geographic coordinates). The API uses RESTful calls issued in JSON format.

Open weather map API , couldn’t get JSON, but getting

Am getting longitude and latitude values from google’s webserivce and passing the values to open weather map api to get the temperature values. Open weather map API , couldn’t get JSON, but getting JSONP and couldnt make asynchronous call. This will cause it to return the value once temperature has been resolved through the ajax call. I

Calling the Open Weather Map API – Hands-on Chatbots with

Stay ahead with the world’s most comprehensive technology and business learning platform. With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

1 Open Weather Map API – YouTube

Click to view on Bing9:32

Jan 19, 2015 · Using the open weather map API. Build Weather App With Ajax Using Open Weather Map API: Current Weather Ajax Request – Duration: 17:17. Uzochukwu Odozi 18,129 views

Author: Mitchell Hudson

Build A Weather App With Ajax Using Open Weather Map API

Open weather map API provides current weather data, weather forecast data as well as historical weather data. With our application, we will make API calls by city name to the open weather map API using Ajax to get response in JSON format.

Getting weather data from Open Weather Map API – Code review

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share …

private float temp;
private float tempMax;
private float tempMin;
You should avoid abbreviating temperature. Temp is commonly used as an abbrevation for temporary and confuses here. In C# we don’t usually use abbreviations. There are exceptions but they consider some well know ones like xml or html . CurrentURL = «http://api.openweathermap.org/data/2.5/weather?q=»
+ location + «&mode=xml&units=metric&APPID=» + APIKEY;
You use some of the new C# 6 features already like the bodyless methods => so you might want to do the same for strings. The above line will become: _currentURL =
$»http://api.openweathermap.org/data/2.5/weather?q={location}» +
$»&mode=xml&units=metric&APPID={APIKEY}»;
Using the var could make you code look much simpler. Consider this using (WebClient client = new WebClient())
{
string xmlContent = client.DownloadString(CurrentURL);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlContent);
return xmlDocument;
}
vs that using (var webClient = new WebClient())
{
var xmlContent = webClient.DownloadString(CurrentURL);
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlContent);
return xmlDocument;
}
XmlDocument
There’s a newer and an easer way to work with xml. Try the XDocument out which is LINQ-capable. You’ll like it. See XDocument or XmlDocument4
You don’t need to explicitly declare a backing field for your properties private string city;
public string City
{
get { return city; }
set { city = value; }
}
You can shorten it to this : public string City { get; set; }
You should restrict your properties as much as possible, and remove the unnecessary ones public string City { get; }
public float Temp { get; private set; }
Those are the only 2 properties you are using the others are redundant and as you can see I’ve added some extra modifiers to your properties now City is a readonly property while Temp has only a private setter You have some conflicts between class members and parameters private XmlDocument GetXML(string CurrentURL)
{
using (WebClient client = new WebClient())
{
string xmlContent = client.DownloadString(currentURL);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlContent);
return xmlDocument;
}
}
You already have variables with names xmlDocument && CurrentURL this might cause some weird behaviour, you should change they’re names. You are inconsistent in your naming : private string CurrentURL;
private XmlDocument xmlDocument;
Both variables are private but one of them starts with capital letter, where usually only public members are following the Pascal case typing, they should both follow the Camel case typing. Same goes for your parameters : public WeatherData(string City)
{
this.City = City;
}

public WeatherAPI(string city)
{
SetCurrentURL(city);
_xmlDocument = GetXML(_currentURL);
}
2 public constructors, one of them has a parameter with Pascal case typing, the other one is following the Camel case typing, instead they should both follow the Camel case typing for they’re parameters. In order to avoid confusion between parameters like currentURL && private class variables with the same name, you can add an underscore for your private class variables : private string _currentURL;
private readonly XmlDocument _xmlDocument;

private XmlDocument GetXML(string currentURL)
{
using (WebClient client = new WebClient())
{
string xmlContent = client.DownloadString(currentURL);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlContent);
return xmlDocument;
}
}
Note that _xmlDocument is also marked as readonly which means you can only give it a value from the constructor.3
I think you have your separation of responsibilities slightly wrong. For example, why are you tying each instance of a WeatherApi to a specific location? It seems to me that it would be better to pass the location in later. The name is also too concerned with the implementation. The caller shouldn’t have to worry that the data is from an API. One other issue with that class is that you do non-trivial work in the constructor. Generally, initialising an object should be cheap. I’d advise that you split this up so that the user creates a WeatherRepository and then calls a GetWeatherData method to actually perform the request. var weatherRepository = new WeatherRepository();
var warsawData = weatherRepository.GetWeatherData(«warsaw»);
Console.WriteLine(warsawData.CurrentTemperature);
Note that I’ve also made GetWeatherData return your WeatherData class rather than populate an XmlDocument . That would be something like: public WeatherData GetWeatherData(string location)
{
var endpoint = GetUrlForLocation(location);
var xmlData = GetXmlFrom(endpoint);
// todo: implement this.
return CreateDataFromXml(xmlDocument);
}

private XmlDocument GetXmlFrom(string endpoint)
{
using (var webClient = new WebClient())
{
var xmlContent = webClient.DownloadString(endpoint);
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlContent);
return xmlDocument;
}
}
If you create your classes to match the xml or add appropriate metadata, the CreateDataFromXml method might be as simple as using an XmlSerializer or DataContractSerializer to deserialize the data directly.3

javascript – OpenWeather API – Pulling JSON data out

I’m writing a little JavaScript to pull information from JSON that contains name, longitude, latitude and openweather API call. What I need is to get the API information out of the API call into the HTML page so you can get the weather forecast for each information.