You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

OpenWeatherMapSharp

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

OpenWeatherMapSharp

An unofficial .NET API wrapper for OpenWeatherMap.org

4.1.0
Source
nugetNuGet
Version published
Maintainers
1
Created
Source

OpenWeatherMapSharp

A .NET client wrapper for https://openweathermap.org written in .NET Standard 2.0

Installation

Install the package via NuGet.

Nuget

Usage

First you need to get a free API key from openweathermap.org. You can create a new account and you will find your API keys on your API keys page.

You need to create a new instance of OpenWeatherMapService passing in the API key. There is also an interface available, if you are using Dependency Injection.

/// <summary>
/// Gets forecast data for a location based 
/// on its geographic coordinates.
/// </summary>
Task<OpenWeatherMapServiceResponse<ForecastRoot>> GetForecastAsync(
    double latitude,
    double longitude,
    LanguageCode language = LanguageCode.EN,
    Unit unit = Unit.Standard);

/// <summary>
/// Gets forecast data based on a city ID.
/// </summary>
[Obsolete]
Task<OpenWeatherMapServiceResponse<ForecastRoot>> GetForecastAsync(
    int cityId,
    LanguageCode language = LanguageCode.EN,
    Unit unit = Unit.Standard);

/// <summary>
/// Gets forecast data based on a city name.
/// </summary>
[Obsolete]
Task<OpenWeatherMapServiceResponse<ForecastRoot>> GetForecastAsync(
    string city,
    LanguageCode language = LanguageCode.EN,
    Unit unit = Unit.Standard);

/// <summary>
/// Gets current weather data for a location based on its geographic coordinates.
/// </summary>
Task<OpenWeatherMapServiceResponse<WeatherRoot>> GetWeatherAsync(
    double latitude,
    double longitude,
    LanguageCode language = LanguageCode.EN,
    Unit unit = Unit.Standard);

/// <summary>
/// Gets current weather data based on a city ID.
/// </summary>
[Obsolete]
Task<OpenWeatherMapServiceResponse<WeatherRoot>> GetWeatherAsync(
    int cityId,
    LanguageCode language = LanguageCode.EN,
    Unit unit = Unit.Standard);

/// <summary>
/// Gets current weather data based on a city name.
/// </summary>
[Obsolete]
Task<OpenWeatherMapServiceResponse<WeatherRoot>> GetWeatherAsync(
    string city,
    LanguageCode language = LanguageCode.EN,
    Unit unit = Unit.Standard);

/// <summary>
/// Gets a list of matching locations for a given query string.
/// </summary>
Task<OpenWeatherMapServiceResponse<List<GeocodeInfo>>> GetLocationByNameAsync(
    string query,
    int limit = 5);

/// <summary>
/// Gets geolocation information based on a ZIP or postal code.
/// </summary>
Task<OpenWeatherMapServiceResponse<GeocodeZipInfo>> GetLocationByZipAsync(
    string zipCode);

/// <summary>
/// Gets a list of matching locations for a given pair of coordinates.
/// </summary>
Task<OpenWeatherMapServiceResponse<List<GeocodeInfo>>> GetLocationByLatLonAsync(
    double latitude,
    double longitude,
    int limit = 5);

/// <summary>
/// Retrieves current air pollution data for a specific location.
/// </summary>
Task<OpenWeatherMapServiceResponse<AirPolutionRoot>> GetAirPolutionAsync(
    double latitude,
    double longitude);

/// <summary>
/// Retrieves forecasted air pollution data for the coming days for a specific location.
/// </summary>
Task<OpenWeatherMapServiceResponse<AirPolutionRoot>> GetAirPolutionForecastAsync(
    double latitude,
    double longitude);

/// <summary>
/// Retrieves historical air pollution data for a specific location and time range.
/// </summary>
Task<OpenWeatherMapServiceResponse<AirPolutionRoot>> GetAirPolutionHistoryAsync(
    double latitude,
    double longitude,
    DateTime start,
    DateTime end);

HINT: Some methods are marked as obsolete, because openweathermap.org marked these methods as depracted. Currently they are all still working, but might be removed in feature releases. They recommend using the methods with latitude and longitude to get the current weather or the forecast.

License

MIT

Keywords

OpenWeatherMap

FAQs

Package last updated on 24 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts