[英]How to use weather API in a website
I am developing a weather application and i am trying to use API from worldweatheronline.com website . 我正在开发天气应用程序,并且尝试使用worldweatheronline.com网站上的API。 but my question here is how do i start to use this weather API in my website.
但是我的问题是如何在我的网站上开始使用此天气API。 as i have already read a question from SO and was not clear about the solution How to integrate the weather api into my website?
因为我已经阅读了SO的一个问题,并且不清楚该解决方案, 如何将weather api集成到我的网站中? .
。 So please help me how to start using these API using Javascript.
因此,请帮助我如何使用Javascript开始使用这些API。 any examples would be appreciated.
任何示例将不胜感激。 and please do remember that i am new to web apps API usage.
并且请记住我是Web应用程序API使用的新手。
the response which i got from the website is 我从网站上得到的答复是
Request URI
http://api.worldweatheronline.com/free/v1/search.ashx?q=Chennai&format=json&key=53jjtnrm9d5jucpmxyyhj7vn
Request Headers { "X-Originating-Ip": "14.140.167.22" } 请求标头{“ X-Originating-Ip”:“ 14.140.167.22”}
Response Headers
{
"Age": "0",
"Cache-Control": "public, no-cache=\"Set-Cookie\", max-age=120",
"Content-Type": "application/json; charset=utf-8",
"Date": "Mon, 16 Sep 2013 09:02:34 GMT",
"Server": "Microsoft-IIS/7.5",
"X-Aspnet-Version": "4.0.30319",
"X-Cache": "MISS",
"X-Mashery-Responder": "prod-j-worker-eu-west-1a-96.mashery.com",
"X-Powered-By": "UKFast Webcelerator",
"Transfer-Encoding": "chunked",
"Connection": "keep-alive"
} }
Response Body
{
"search_api": {
"result": [{
"areaName": [{
"value": "Chennai"
}],
"country": [{
"value": "India"
}],
"latitude": "13.083",
"longitude": "80.283",
"population": "0",
"region": [{
"value": "Tamil Nadu"
}],
"weatherUrl": [{
"value": "http:\/\/www.worldweatheronline.com\/Chennai-weather\/Tamil-Nadu\/IN.aspx"
}]
}]
}
}
Please visit http://api.jquery.com/jQuery.ajax/ ,for how to make a call to a web service. 请访问http://api.jquery.com/jQuery.ajax/ ,以了解如何调用网络服务。
For your weather API, please register , get the keys 对于您的天气API,请注册,获取密钥
$.ajax(
{
Type: "GET",
contentType: "application/json",
url: "http://api.worldweatheronline.com/free/v1/weather.ashx?q=London&format=json&num_of_days=5&key=yourkey",
success: function (msg) {
$("#success").text(msg);
}
});
This is an example for getting local weather. 这是获取当地天气的示例。
You can also do it like this via php: 您也可以通过php这样做:
$url="http://api.worldweatheronline.com/free/v1/weather.ashx?q=[LOCATION]&format=json&num_of_days=5&key=[YOUR_KEY]";
$json=file_get_contents($url);
$data=json_decode($json,true);
//var_dump($data);
echo $data['data']['weather'][0]['tempMaxF']."<br />";
That's what I'm using because I just have it run on load and I'm not using it in an app; 这就是我正在使用的,因为我只是让它在负载下运行,而我没有在应用程序中使用它。 just on a web page.
只是在网页上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.