forked from tredmann/forecast.io-php-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
51 lines (32 loc) · 1.06 KB
/
example.php
File metadata and controls
51 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
include('lib/forecast.io.php');
$api_key = '<your_api_key>';
$latitude = '52.4308';
$longitude = '13.2588';
$forecast = new ForecastIO($api_key);
/*
* GET CURRENT CONDITIONS
*/
$condition = $forecast->getCurrentConditions($latitude, $longitude);
echo $condition->getTemperature();
/*
* GET HOURLY CONDITIONS FOR TODAY
*/
$conditions_today = $forecast->getForecastToday($latitude, $longitude);
foreach($conditions_today as $cond) {
echo $cond->getTime('H:i:s') . ': ' . $cond->getTemperature();
}
/*
* GET DAILY CONDITIONS FOR NEXT 7 DAYS
*/
$conditions_week = $forecast->getForecastWeek($latitude, $longitude);
foreach($conditions_week as $conditions) {
echo $conditions->getTime('Y.m.d') . ': ' . $conditions->getMaxTemperature();
}
/*
* GET HISTORICAL CONDITIONS
*/
$condition = $forecast->getHistoricalConditions($latitude, $longitude, strtotime('2010-10-10T14:00:00-0700'));
// strtotime('2010-10-10T14:00:00-0700') gives timestamp for Pacfic Time... DST shouldn't matter since should be same day
echo $condition->getMaxTemperature();
?>