测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
发布最新版本 | 2014年12月 |
由 Jonathan Field 维护。
依赖关系 | |
AFNetworking | >= 0 |
APTimeZones | >= 0 |
Objective-C iOS / Mac OS X 包装器,以便轻松操作Open Weather Map API
Open Weather Map API包装器 + MapView示例,在地图上添加一个标记来检索该位置的当前天气数据
将JFWeatherMapManager添加到您的项目中
导入以下头文件
#import "JFWeatherData.h"
#import "JFWeatherManager.h"
#import "DataModels.h"
如果您使用示例项目,请确保在视图控制器中设置您的API密钥,这不是必须的,如果您选择不使用API密钥,只需在后面的检索命令中传递nil即可
static NSString *API_KEY = @"YOUR_API_KEY_HERE";
创建对JFWeatherManager对象的引用并调用检索函数
JFWeatherManager *weatherManager = [[JFWeatherManager alloc]init];
[weatherManager fetchWeatherDataForLatitude:toAdd.coordinate.latitude andLongitude:toAdd.coordinate.longitude withAPIKeyOrNil:API_KEY :^(JFWeatherData *returnedWeatherData){
NSLog(@"Latitude %.3f",[returnedWeatherData latitudeCoordinateOfRequest]);
NSLog(@"Longitude %.3f",[returnedWeatherData longitudeCoordinateOfRequest]);
NSLog(@"Country %@",[returnedWeatherData countryCode]);
NSLog(@"Conditions are %@",[returnedWeatherData currentConditionsTextualDescription]);
NSLog(@"Temperature is %f",[returnedWeatherData temperatureInUnitFormat:kTemperatureCelcius]);
NSLog(@"Sunrise is %@",[returnedWeatherData sunriseTime]);
NSLog(@"Sunset is %@",[returnedWeatherData sunsetTime]);
NSLog(@"Hours of Day Light are %@",[returnedWeatherData dayLightHours]);
NSLog(@"Humidity is %@",[returnedWeatherData humidityPercentage]);
NSLog(@"Pressure is %0.1f",[returnedWeatherData pressureInUnitFormat:kPressureHectopascal]);
NSLog(@"Wind Speed is %0.1f",[returnedWeatherData windSpeedInUnitFormat:kWindSpeedMPH]);
NSLog(@"Wind Direction is %@",[returnedWeatherData windDirectionInGeographicalDirection]);
NSLog(@"Cloud Coverage %@",[returnedWeatherData cloudCovergePercentage]);
NSLog(@"Rainfall Over Next 3h is %0.1fmm",[returnedWeatherData rainFallVolumeOver3HoursInMillimeters]);
NSLog(@"SnowFall Over Next 3h is %0.1fmm",[returnedWeatherData snowFallVolumeOver3HoursInMillimeters]);
}];
API可以返回的数据和格式如下
- (NSString *)currentConditionsTextualDescription; //e.g Broken Clouds
- (double)temperatureInUnitFormat:(TemperatureUnit)temperatureUnit; //e.g 3.0°C , Temperature Available in Kelvin, Celsius and Fahrenheit
- (double)pressureInUnitFormat:(PressureUnit)pressureUnit; //e.g 1007.0 hPA , Pressure Available in Hectopascal, and Pascal
- (NSString *)sunriseTime; //e.g 06:33 (Time Shown is Localised based on Latitude and Longitude of the request)
- (NSString *)sunsetTime; //e.g 19:32 (Time Shown is Localised based on Latitude and Longitude of the request)
- (NSString *)dayLightHours; //e.g 12:15
- (NSString *)humidityPercentage; //e.g 88%
- (NSString *)cloudCovergePercentage; //e.g 32%
- (double)windSpeedInUnitFormat:(WindSpeedUnit)windSpeedUnit; //e.g 20.8 MPH, Wind Speed Available in Meters Per Second, Miles Per Hour, Kilometres Per Hour
- (double)windDirectionInDegrees; //e.g 320°
- (NSString *)windDirectionInGeographicalDirection; //e.g N (North)
- (double)rainFallVolumeOver3HoursInMillimeters; //e.g 3mm
- (double)snowFallVolumeOver3HoursInMillimeters; //e.g 7mm
- (double)latitudeCoordinateOfRequest; //e.g 32.79
- (double)longitudeCoordinateOfRequest; //e.g -96.0
- (NSString *)countryCode; // E.g. GB / US / DE
温度格式(开尔文、摄氏度、华氏度)
typedef enum temperatureUnits {kTemperatureKelvin, kTemperatureCelcius, kTemperatureFarenheit} TemperatureUnit;
压力格式(百帕斯卡、帕斯卡)
typedef enum pressureUnits {kPressureHectopascal, kPressurePascal} PressureUnit;
风速单位(米/秒、英里/小时、千米/小时)
typedef enum windSpeedUnits {kWindSpeedMPS, kWindSpeedMPH, kWindSpeedKPH} WindSpeedUnit;
归属(特别感谢)
OpenWeatherMap API http://openweathermap.org 为他们出色的API!AFNetworking创建iOS和MacOSX上最好的网络库(以此为项目捆绑) http://afnetworking.com APTimeZones提供基于纬度和经度定位时区出色的库(与本项目捆绑) https://github.com/Alterplay/APTimeZones
联系方式 - Jonathan Field | http://jonathanfield.me