Code Monkey home page Code Monkey logo

openweathermapapi's Introduction

Notice: This project isn't under active development.

I recomend you trying one of the the other libraries like:


![OpenWeatherMapAPI](https://raw.github.com/adba/OpenWeatherMapAPI/master/hero.png)

Open Weather Map iOS API

This projects allows you to quickly and easily fetch data from openweathermap.org.

API Changes

Version 0.0.5

The methods for getting the daily forecast have changed names. So instead of: dailyForecastWeatherByCityName:withCount:withCallback: they are now called: dailyForecastWeatherByCityName:withCount:andCallback:

Added new methods for setting the lang parameter to the api:

 - (void) setLangWithPreferedLanguage;
 - (void) setLang:(NSString *) lang;
 - (NSString *) lang;

The method setLangWithPreferedLanguage sets the lang parameter according to the prefered language on the phone.

Usage

Installation

Using the API is really simple if you have CocoaPods installed.

  1. Add the dependency to your Podfile

    pod 'OpenWeatherMapAPI', '~> 0.0.5'
  2. Include the header #import "OWMWeatherAPI.h".

  3. Setup the api:

    // Setup weather api
    OWMWeatherAPI *weatherAPI = [[OWMWeatherAPI alloc] initWithAPIKey:@"YOUR-API-KEY"];
  4. Select the default temperature format (defaults to Celsius)

    [weatherAPI setTemperatureFormat:kOWMTempCelcius];

Getting data

The api is at this time just simple wrapper for the http-api. So to get the current weather for the city Odense you can call it like this:

[weatherAPI currentWeatherByCityName:@"Odense" withCallback:^(NSError *error, NSDictionary *result) {
    if (error) {
        // handle the error
        return;
    }

    // The data is ready

    NSString *cityName = result[@"name"];
    NSNumber *currentTemp = result[@"main"][@"temp"];

}]

The result data is a NSDictionary that looks like this (json):

    {
        coord: {
            lon: 10.38831,
            lat: 55.395939
        },
        sys: {
            country: "DK",
            sunrise: 1371695759, // this is an NSDate
            sunset: 1371758660   // this is also converted to a NSDate
        },
        weather: [
            {
                id: 800,
                main: "Clear",
                description: "Sky is Clear",
                icon: "01d"
            }
        ],
        base: "global stations",
        main: {
            temp: 295.006,      // this is the the temperature format you´ve selected
            temp_min: 295.006,  //                 --"--
            temp_max: 295.006,  //                 --"--
            pressure: 1020.58,
            sea_level: 1023.73,
            grnd_level: 1020.58,
            humidity: 80
        },
        wind: {
            speed: 6.47,
            deg: 40.0018
        },
        clouds: {
            all: 0
        },
        dt: 1371756382,
        id: 2615876,
        name: "Odense",
        cod: 200
    }

See an example in the OWMViewController.m file.

Methods

The following methods are available at this time:

current weather

current weather by city name:

    -(void) currentWeatherByCityName:(NSString *) name
                        withCallback:( void (^)( NSError* error, NSDictionary *result ) )callback;

current weather by coordinate:

    -(void) currentWeatherByCoordinate:(CLLocationCoordinate2D) coordinate
                          withCallback:( void (^)( NSError* error, NSDictionary *result ) )callback;

current weather by city id:

    -(void) currentWeatherByCityId:(NSString *) cityId
                      withCallback:( void (^)( NSError* error, NSDictionary *result ) )callback;

forecasts (3 hour intervals)

forecast by city name:

    -(void) forecastWeatherByCityName:(NSString *) name
                         withCallback:( void (^)( NSError* error, NSDictionary *result ) )callback;

forecast by coordinate:

    -(void) forecastWeatherByCoordinate:(CLLocationCoordinate2D) coordinate
                           withCallback:( void (^)( NSError* error, NSDictionary *result ) )callback;

forecast by city id:

    -(void) forecastWeatherByCityId:(NSString *) cityId
                       withCallback:( void (^)( NSError* error, NSDictionary *result ) )callback;

daily forecasts

daily forecast by city name:

    -(void) dailyForecastWeatherByCityName:(NSString *) name
                                 withCount:(int) count
                              andCallback:( void (^)( NSError* error, NSDictionary *result ) )callback;

daily forecast by coordinates:

    -(void) dailyForecastWeatherByCoordinate:(CLLocationCoordinate2D) coordinate
                                   withCount:(int) count
                                andCallback:( void (^)( NSError* error, NSDictionary *result ) )callback;

daily forecast by city id:

   -(void) dailyForecastWeatherByCityId:(NSString *) cityId
                              withCount:(int) count
                           andCallback:( void (^)( NSError* error, NSDictionary *result ) )callback;

searching

search for a city by name:

   -(void) searchForCityName:(NSString *) name
                   withCount:(int) count
                andCallback:( void (^)( NSError* error, NSDictionary *result ) )callback;

openweathermapapi's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openweathermapapi's Issues

Use HTTPS instead of HTTP for ATS

In the latest versions of iOS, apple block http queries since they are insecure, unless temporarily whitelisted. Would it be possible to update the framework to use HTTPS so we don't have to use that workaround (which will soon be completely banned I believe)?

Some one said at OpenWeatherMap.Org is not that reliable

Thanks for open sourcing the OpenWeatherMapAPI and as a side note for guest
"The API in its current state is very unreliable (pressure values are way off, inconsitent API and return objects) and doesnt appear to be maintained properly.

I thusly suggest you go open source. OpenWeatherMap.org sounds like it is open source but in reality it is not. By going open source others (like me) could help tidying stuff up and making it more reliable."

http://bugs.openweathermap.org/issues/68

I cannot use cocoa pod to install this api

Hi, I try to install this api by cocoa pod, but it doesn't work, the terminal shows me some requirement. I don't know what is that mean. Is there any other way to use this api? Thanks a lot!

getting temperature for dailyForecast method

Currently I found that the method that returns a daily forecast for up to 14 days just displays the description of the weather i general on that day like: "Clear" or "Sunny"....
While logging I found that temperature for that day is given in the xml but for some reason isn't given to us to be able to use it maybe it's my code I don't know... If you are wondering how I'm using the code just tell me and I can post it.

currentWeatherByCoordinate

Need to change ,lng to &lon

NSString *method = [NSString stringWithFormat:@"/weather?lat=%f,lng=%f",
coordinate.latitude, coordinate.longitude ];

TO:

NSString *method = [NSString stringWithFormat:@"/weather?lat=%f&lon=%f",
coordinate.latitude, coordinate.longitude ];

Multilingual support

Nice work! Good to have the ability to pass in the lang parameter or better have it get the default language from the device and add it to the API request, if it is a supported language.

To get preferred:
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];

Current supported:
English - en, Russian - ru, Italian - it, Spanish - sp, Ukrainian - ua, German - de, Portuguese - pt, Romanian - ro, Polish - pl, Finnish - fi, Dutch - nl, French - fr, Bulgarian - bg, Swedish - se, Chinese Traditional - zh_tw, Chinese Simplified - zh_cn, Turkish - tr

Thanks,
Tim

Not called

Hi,

Is there any reason why the block method is never called when I create a request?
I do it in two viewControllers, the first one and then in another one. It works in the first one but in the second one the block code never gets called. Is there some kind of a issue and I have to call it differently?

Thanks, Kristers.

Forecast date

Hi,

Is it possible to get a date for a daily forecast? When getting a daily forecast I get all the temperatures etc, but how can I know what day is it for , it doesn't return any dates.
Any solution?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.