Get weather at current location from latitude and longitude in iPhone

I have the current location Latitude [17.382042000000000000]

and Longitude[78.481727299999990000].

Is there a way to find out the weather based on these latitudes and longitudes?
Are there any third party free APIs to find weather based on these values?
Can anyone provide me with some guidelines or urls for this problem?

+3


source to share


5 answers


You can use the following url. Change latitude and longitude based on your requirement.

http://api.wunderground.com/auto/wui/geo/GeoLookupXML /index.xml?query=17.3820420000000000006,78.48172729999999000

To get the current weather condition, you can use the following API endpoint. The only thing you need is to generate an API key from their site. - http://www.wunderground.com/weather/api



Here is the endpoint: http://api.wunderground.com/api/API_KEY/conditions/forecast/alert/q/17.382042000000000000,78.48172729999999000.json

Replace API_KEY from the generated API key.

+3


source


+(NSDictionary*)getWeatherForLocation:(CLLocation*)location
{
 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

 NSString *stringURL=[NSString stringWithFormat:@"http://api.wunderground.com/api/yourAPIKey/geolookup/forecast10day/q/%f,%f.json",location.coordinate.latitude,location.coordinate.longitude];

 [request setURL:[NSURL URLWithString:stringURL]];

 NSURLResponse * response = nil;
 NSError * error = nil;
 NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
 NSString *stringData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

 NSDictionary *dictionary=[stringData objectFromJSONString];

 locationDic=[[NSDictionary alloc] initWithDictionary:[dictionary valueForKey:@"location"]];
 NSLog(@"locations is %@",locationDic);

 return [dictionary valueForKey:@"forecast"];
}

      

you can use api directly by passing lat long as



http://api.wunderground.com/api/APPKey/geolookup/forecast10day/q/37.785834,-122.406417.json

+1


source


Also, I recommend checking out the OpenWeatherMap API . You can use it for free and I think it can help you. For example, in your case, the url might look like this:

api.openweathermap.org/data/2.5/weather?lat=17.38&lon=78.48

      

It will return data in JSON format. See the API documentation for details.

+1


source


Yes, there are several APIs for this. Have a look at some of the other StackOverflow questions:

Get weather forecast by geolocation html5

eg. The weather error has an API method that takes lat / long positions:

http://developer.weatherbug.com/docs/read/WeatherBug_API_JSON

I'm sure there are many more. Just try a few and see which one works for you.

0


source


yahoo provides weather services - on iPhone, you need

1) get your longitude & latitude using CoreLocation
2) use

http://query.yahooapis.com/v1/public/yql?q=select+place+from+flickr.places+where+lat=%f+and+lon=%f

to get a woeid (WhereOnEarth ID)

1)use

    http://weather.yahooapis.com/forecastrss?w=%@&u=c

      

to get a weather report

0


source







All Articles