使用 Yahoo API,如何获取与特定前缀匹配且具有可用天气数据的位置列表
我有一个应用程序(除其他外)使用 Yahoo Weather API 来显示用户选择的位置的天气状况。
在用户可以输入位置的配置对话框中,我很乐意提供自动完成功能,以便当用户输入位置名称时,会建议匹配城市的列表。
我可以使用 YQL 来获取与前缀匹配的位置,即:
select * from geo.places where text = 'Vie*'
但问题是并非每个位置都有与之关联的气象站,而且我我很想在我的自动完成列表中跳过这些。
使用社区表(名为weather.woeid的表),以下查询将使用天气API连接先前的查询,仅返回有气象站的位置:
select location from Weather.woeid where w in (select woeid from geo.places where text = 'Vie*')
这几乎解决了我的问题,除了之前的查询(产生与天气 api 调用相同的结果)不返回 WOEID 或任何我可以直接使用的标识符配置完成后查询天气API。如何捕获连接参数 w 的值?我尝试了类似 select w, location ...
但这似乎不起作用。
是否有其他方法可以获取与特定前缀匹配的位置列表(包括 WOEID),并且有与其关联的天气数据?
I have an app that (among other things) uses Yahoo Weather API to display weather conditions for a location selected by user.
In the configuration dialog where user can enter the location, I'd love to offer autocompletion so that while user is typing location name, list of matching cities is suggested.
I can use YQL to fetch locations matching the prefix, i.e.:
select * from geo.places where text = 'Vie*'
but the problem is that not every location has a weather station associated with it and I'd love to skip these in my autocompletion list.
Using community tables (table called weather.woeid), following query will join previous query with the weather api, returning only locations that do have weather stations:
select location from weather.woeid where w in (select woeid from geo.places where text = 'Vie*')
This almost solves my problem, except for the fact that previous query (which produces same result as weather api call) doesn't return WOEID nor any kind of identifier I can use to directly query the Weather API after configuration. How can I capture the value of join parameter w? I tried something like select w, location ...
but that doesn't seem to work.
Is there any other way to get list of locations (incl. WOEID) matching certain prefix that have weather data associated with them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,YQL 不可能将值从 Sub-Select(内部 SELECT 语句)传递到外部 SELECT,如果我理解正确的话,这就是您想要做的。
根据您的用例,我想提出另一个解决方案:
我假设具有与之关联的气象站的位置列表是相对静态的,这意味着该列表不会经常更改。如果是这种情况,那么每次使用 YQL 重新生成该列表在性能方面并不是非常理想。相反,我会离线生成该列表,将其存储在文件或 MySQL 或其他位置,然后使用该静态列表来响应自动完成字段的 AJAX 调用。
该静态列表中的数据可能如下所示:
用户选择位置并按 Enter 键后,您可以将 YQL 查询发送到weather.woeid,以根据 WOEID 查找当前天气。
Afaik it is not possible with YQL to pass through values from the Sub-Select (the inner SELECT statement) to the outer SELECT, which I is what you want to do if I understand you correctly.
Based on your use case I want to propose another solution though:
I assume that the list of locations that have a weather station associated with them is relatively static, meaning this list does not change very often. If that is the case then it would not be very optimal in terms of performance to regenerate that list every time with YQL. Instead I would generate that list offline, store it in a file or MySQL or elsewhere and then just use that static list to answer to the AJAX call of your autocomplete field.
The data in that static list could look something like this:
Once the user has selected a location and pressed enter, then you can send the YQL query to weather.woeid to look up the current weather based on the WOEID.