First of all We are not getting any zip code or postal code for India.
Also Google API has been stop working.
I used yahoo api to find out weather.
Here is the code that might help someone
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
[self.locationManager stopUpdatingLocation];
self.location = newLocation;
NSString *linkForWoeid = [NSString stringWithFormat:@" http://where.yahooapis.com/geocode?location=%f,%f&flags=J&gflags=R&appid=zHgnBS4m",self.location.coordinate.latitude,self.location.coordinate.longitude];
NSURL *woeidURL = [NSURL URLWithString:linkForWoeid];
NSData *WoeidData = [NSData dataWithContentsOfURL:woeidURL];
if (WoeidData != NULL)
{
NSError *woeiderr = nil;
NSDictionary *aDicWOEIDResp = [NSJSONSerialization JSONObjectWithData:WoeidData options:NSJSONReadingMutableContainers error:&woeiderr];
NSDictionary *aDictWOEID = [[[[aDicWOEIDResp objectForKey:@"ResultSet"]objectForKey:@"Results"]objectAtIndex:0]objectForKey:@"woeid"];
NSString *address=[NSString stringWithFormat:@"http://weather.yahooapis.com/forecastrss?w=%@",aDictWOEID];
ICB_WeatherConditions *icbWeather = [[ICB_WeatherConditions alloc] initWithQuery:address];
}
#import "ICB_WeatherConditions.m"
- (ICB_WeatherConditions *)initWithQuery:(NSString *)query
{
if (self = [super init])
{
NSURL *url = [NSURL URLWithString:query];
CXMLDocument *parser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease];
NSDictionary *namespaceMedia = [NSDictionary dictionaryWithObject:@"http://xml.weather.yahoo.com/ns/rss/1.0" forKey:@"yweather"];
NSArray *nodes = [parser nodesForXPath:@"//channel" error:nil];
for (CXMLNode *node in nodes) {
if ([node kind] == CXMLElementKind)
{
CXMLElement *element = (CXMLElement *)node;
for(int i=0;i<[element childCount];i++)
{
NSString *strKey = [[element childAtIndex:i] name];
if([strKey isEqual:@"location"])
{
location = [self stringForXPath:@"@city" ofNode:[element childAtIndex:i] withNameSpace:namespaceMedia];
}
else if([strKey isEqual:@"item"])
{
NSArray *nodeItem = [element nodesForXPath:@"//item" error:nil];
CXMLElement *elementItem = [nodeItem objectAtIndex:0];
for(int j=0;j<[elementItem childCount];j++){
NSString *strKeyItem = [[elementItem childAtIndex:j] name];
if([strKeyItem isEqual:@"condition"]){
condition =[self stringForXPath:@"@text" ofNode:[elementItem childAtIndex:j] withNameSpace:namespaceMedia];
currentTemp = [[self stringForXPath:@"@temp" ofNode:[elementItem childAtIndex:j] withNameSpace:namespaceMedia] intValue];
}
else if([strKeyItem isEqual:@"forecast"])
{
NSString *date = [self stringForXPath:@"@date" ofNode:[elementItem childAtIndex:j] withNameSpace:namespaceMedia];
NSDate *curDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"dd MMM yyyy";
NSString *strCurDate = [dateFormatter stringFromDate:curDate];
if([date isEqual:strCurDate])
{
highTemp = [[self stringForXPath:@"@high" ofNode:[elementItem childAtIndex:j] withNameSpace:namespaceMedia] intValue];
lowTemp = [[self stringForXPath:@"@low" ofNode:[elementItem childAtIndex:j] withNameSpace:namespaceMedia] intValue];
}
}
}
}
else
continue;
}
}
}
}
return self;
}
This is how I get the weather Details. In my case I only needed Location,Condition,High Temp,Low Temp,Current Temp.