在iPhone中从纬度和经度获取当前位置的天气

时间:2022-08-22 10:23:09

I have current location Latitude[17.382042000000000000] and Longitude[78.481727299999990000].

我有当前位置纬度[17.382042000000000000]和经度[78.481727299999990000]。

Is there any way find out the weather based on these Latitude and Longitude?
Is there any third party free APIs for finding the weather based on these values?
Can any one provide me some guidelines or URLs for this problem?

有没有办法根据这些纬度和经度找出天气?是否有任何第三方免费API可根据这些值查找天气?任何人都可以为我提供一些针对此问题的指南或网址吗?

5 个解决方案

#1


3  

You can use the following URL. Change Latitude and Longitude based on your requirement.

您可以使用以下URL。根据您的要求更改纬度和经度。

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 have to Generate API key from their site. - http://www.wunderground.com/weather/api

要获取当前天气状况,您可以使用以下API端点。您必须从他们的站点生成API密钥。 - 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

这是终点:http://api.wunderground.com/api/API_KEY/conditions/forecast/alert/q/17.382042000000000000,78.48172729999999000.json

Replace the API_KEY from you generated API key.

从您生成的API密钥替换API_KEY。

#2


2  

Also, I'd recommend to check OpenWeatherMap API. You can use it for free and I think it can help you. For instance, in your case a URL might look like this:

另外,我建议检查OpenWeatherMap API。你可以免费使用它,我认为它可以帮助你。例如,在您的情况下,URL可能如下所示:

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

It will return a data in JSON format. For more details please check the API documentation.

它将以JSON格式返回数据。有关更多详细信息,请查看API文档。

#3


1  

+(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 directly use api by passing lat long as

你可以通过传递lat long来直接使用api

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

#4


0  

Yes, there are a few APIs available for this. Look at some of the other * questions:

是的,有一些API可用于此。看看其他一些*问题:

Get weather by html5 geolocation

通过html5地理位置获取天气

e.g. Weather bug has an API method that takes lat / long positions:

例如Weather bug有一个采用纬度/多头位置的API方法:

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

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

我相信还有更多。试试看几个,看看哪个适合你。

#5


0  

yahoo provides a weather service - on the iPhone you need to

雅虎提供天气服务 - 在iPhone上你需要

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 your weather report

得到你的天气预报

#1


3  

You can use the following URL. Change Latitude and Longitude based on your requirement.

您可以使用以下URL。根据您的要求更改纬度和经度。

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 have to Generate API key from their site. - http://www.wunderground.com/weather/api

要获取当前天气状况,您可以使用以下API端点。您必须从他们的站点生成API密钥。 - 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

这是终点:http://api.wunderground.com/api/API_KEY/conditions/forecast/alert/q/17.382042000000000000,78.48172729999999000.json

Replace the API_KEY from you generated API key.

从您生成的API密钥替换API_KEY。

#2


2  

Also, I'd recommend to check OpenWeatherMap API. You can use it for free and I think it can help you. For instance, in your case a URL might look like this:

另外,我建议检查OpenWeatherMap API。你可以免费使用它,我认为它可以帮助你。例如,在您的情况下,URL可能如下所示:

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

It will return a data in JSON format. For more details please check the API documentation.

它将以JSON格式返回数据。有关更多详细信息,请查看API文档。

#3


1  

+(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 directly use api by passing lat long as

你可以通过传递lat long来直接使用api

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

#4


0  

Yes, there are a few APIs available for this. Look at some of the other * questions:

是的,有一些API可用于此。看看其他一些*问题:

Get weather by html5 geolocation

通过html5地理位置获取天气

e.g. Weather bug has an API method that takes lat / long positions:

例如Weather bug有一个采用纬度/多头位置的API方法:

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

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

我相信还有更多。试试看几个,看看哪个适合你。

#5


0  

yahoo provides a weather service - on the iPhone you need to

雅虎提供天气服务 - 在iPhone上你需要

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 your weather report

得到你的天气预报