Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6391173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:38:24+00:00 2026-05-25T03:38:24+00:00

I am trying to get weather information for an iPhone application. If I enter

  • 0

I am trying to get weather information for an iPhone application. If I enter a 5 digit zipcode, the code is working. However, I want to make sure that if the user does not enter a valid city or zip code, it doesnt crash. The problem is that with Google Weather API, the XML data reads “city data” when a valid place is entered, and “problem_cause data” when it is not a valid place. Please help!

-(IBAction) getlocation {
    NSString *locationentered = location.text;
    if ([locationentered isEqualToString: @""])  {
    locationlabel.text = @"Please Enter a Location";
}
    else {

    NSString * locationen =  locationentered;
    NSString * address = @"http://www.google.com/ig/api?weather=";
    NSString * request = [NSString stringWithFormat:@"%@%@",address,locationen];
    NSURL * URL = [NSURL URLWithString:request];
    NSError * error;    
    NSString* XML = [NSString stringWithContentsOfURL:URL encoding:NSASCIIStringEncoding error:&error];
    NSString * temptoday = [[[[XML componentsSeparatedByString:@"city data=\""] objectAtIndex:1] componentsSeparatedByString:@"\""] objectAtIndex:0];


    NSString * errorlocation = [[[[XML componentsSeparatedByString:@"problem_cause data=\""] objectAtIndex:1] componentsSeparatedByString:@"\""] objectAtIndex:0];
    if ([errorlocation isEqualToString: @""]) {
    locationlabel.text = @"Invalid Location";
    }


if ([temptoday isEqualToString:@"(null)"]) {

        locationlabel.text = @"Location present";
    }
else {

    locationlabel.text = temptoday;

    }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:38:24+00:00Added an answer on May 25, 2026 at 3:38 am

    The result is XML so use an XMLParser to look at it. In this case the standard Cocoa one is NSXMLParser and then setup a delegate which will get called for each element.

    For the start of an element you will get called parser:didStartElement:namespaceURI:qualifiedName:attributes: and this will pass in the element name in this case problem_cause or forecast_information depending if the input was good.

    See Apple’s Event-Driven XML Programming Guide for more
    or look at DOM parsers from this Stack Exchange question

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to adapt a code to extract information from wunderground. However the script
I'm am trying to get a list of weather information for 8 locations. I'm
Trying to get comfortable with jQuery and I have encountered some sample code that
I'm trying to use feedparser to get some data from yahoos weather rss. It
I'm trying to get the Yahoo Weather with JavaScript. I originally made a proxy,
I'm trying to make a script that outputs user names based on weather they
i am trying to get the info from yahoo weather in different languages http://developer.yahoo.com/weather/
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I'm trying to pull the weather from the weather network. This code gives it
I was trying to make weather based PHP script to show weather related data.But,I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.