我搜索了一会儿,但没有找到类似我的问题的内容。
我想使用雅虎天气API,例如:http://weather.yahooapis.com/forecastrss?w=4097
我不知道在我的情况下WOEID是什么,但我有纬度和经度坐标。
所以我的问题是: 有没有办法通过使用纬度和经度坐标来获取地方的WOEID?
我搜索了一会儿,但没有找到类似我的问题的内容。
我想使用雅虎天气API,例如:http://weather.yahooapis.com/forecastrss?w=4097
我不知道在我的情况下WOEID是什么,但我有纬度和经度坐标。
所以我的问题是: 有没有办法通过使用纬度和经度坐标来获取地方的WOEID?
现在可以通过最近发布的PlaceFinder API来实现。感谢Yahoo! 提供了地理拼图中又一个重要的组成部分。
雅虎地点查找API允许你查找一个纬度/经度对应的WOEID。考虑下面的这个示例Web服务方法调用:
http://where.yahooapis.com/geocode?location=37.42,-122.12&flags=J&gflags=R&appid=zHgnBS4m
你可以根据自己的需求更改请求参数,详见Yahoo! PlaceFinder API文档。同时,你需要用你的Yahoo! appid替换掉appid,你可以在这里创建一个。{
"ResultSet": {
"version": "1.0",
"Error": 0,
"ErrorMessage": "No error",
"Locale": "us_US",
"Quality": 99,
"Found": 1,
"Results": [
{
"quality": 99,
"latitude": "37.420000",
"longitude": "-122.120000",
"offsetlat": "37.420000",
"offsetlon": "-122.120000",
"radius": 500,
"name": "37.42,-122.12",
"line1": "3589 Bryant St",
"line2": "Palo Alto, CA 94306-4207",
"line3": "",
"line4": "United States",
"house": "3589",
"street": "Bryant St",
"xstreet": "",
"unittype": "",
"unit": "",
"postal": "94306-4207",
"neighborhood": "",
"city": "Palo Alto",
"county": "Santa Clara County",
"state": "California",
"country": "United States",
"countrycode": "US",
"statecode": "CA",
"countycode": "",
"hash": "",
"woeid": 12797284,
"woetype": 11,
"uzip": "94306"
}
]
}
}
这并不使用雅虎的API,但我找到了这篇博客文章:http://geomojo.org/?p=38
提到了这个服务:http://www.geomojo.org/cgi-bin/reversegeocoder.cgi?long=-117.699444&lat=35.4775
也许你可以用它?它解决了我的问题,希望能帮助你解决问题。
首先使用以下代码从纬度/经度获取城市名称。
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
[geocoder reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"cityname - %@",placemark.locality);
}];
{ "l" : { "gprid" : "eIL89mltSzSfgDWdP7uyBA" },
"q" : "sydney",
"r" : [ { "d" : "pt:iso=AU&woeid=1105779&lon=151.021&lat=-33.8563&s=New South Wales&c=Australia&sc=NSW&n=Sydney, Australia",
"k" : "Sydney"
} ]
}
不必使用经度和纬度,您可以使用当前在线IP地址获取城市名称,然后使用Yahoo GeoPlanet Web服务获取WOEID。请按照本教程获取详细信息:http://4rapiddev.com/php/get-woeid-of-a-city-name-from-ip-address-with-php/
在YDN论坛上有一个关于这个问题的主题 http://developer.yahoo.net/forum/index.php?showtopic=69
看起来它被埋在待办列表中,自2008年以来“将一组经纬度坐标映射到WOEID的能力已被确定为一个有价值的特性,并且它在我们的增强请求列表上。”
其他引言;
“Flickr有一种方法:flickr.places.findByLatLon返回WOEID,但它们将坐标截断为三位小数。”
在这个主题中,雅虎公司的开发者还建议使用http://geomojo.org/?p=38上的建议作为临时解决方案。
原先的Yahoo天气API已经被弃用。新的Yahoo天气API需要一个查询字符串来获取天气。
使用以下查询字符串通过纬度和经度获取天气数据 -
"https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\"(" + latitude + "," + longitude + ")\")&format=json"
https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="(${lat},${lon})")&format=json
- Shaurya