gpt4 book ai didi

javascript - 从城市名称获取 WOEID?

转载 作者:数据小太阳 更新时间:2023-10-29 05:13:13 25 4
gpt4 key购买 nike

我正在使用 Google Weather API 获取天气信息,但显然 Google 已停止其服务。我现在正尝试切换到 Yahoo Weather API。

var WOEID = 2502265;  //random WOEID
$.ajax({
url: "http://weather.yahooapis.com/forecastjson?w=" + WOEID + "&u=c",
dataType: 'json',
success: function(data) {
console.log(data);
}
});

但是,有没有办法只通过 JavaScript 获取 WOEID?因为那时我可以做

http://www.google.com/ig/api?hl=en&weather=NYC

就是这样。

它在 Yahoo weather API page 上说,

To find your WOEID, browse or search for your city from the Weather home page. The WOEID is in the URL for the forecast page for that city. You can also get the WOEID by entering your zip code on the home page.

但我想通过 JavaScript 获取它,而不是手动去 weather.yahoo.com 并找出 WOEID。

不要关心跨源策略,因为我在 Chrome 扩展程序中使用它并且它不适用。

最佳答案

好的,我从您的评论中了解到您到底想要什么

你有一个地名,你想使用 javascript ajax 调用获取该地名的 WOEID

获取它的 url 未定义任何您必须使用 GeoPlanet 服务将地点解析为 WOEID 的地方

http://where.yahooapis.com/v1/places.q('Place name')?appid=[yourappidhere] 

或者你必须像这样使用 Direct YQL(在你的城市名称的 url 中使用百分比编码)并尝试对此进行 ajax 调用

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22Place%20name%22&format=xml

关于javascript - 从城市名称获取 WOEID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12434591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com