-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetWeatherInfo.php
39 lines (33 loc) · 969 Bytes
/
GetWeatherInfo.php
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
<?php
include 'includes/login-check.php';
include 'includes/database.php';
/* Default Location is set here first */
$city="Sydney";
$country="Australia";
/*Getting Location info*/
$location_url="http://ip-api.com/json/";
$location_contents=file_get_contents($location_url);
$location_json=json_decode($location_contents,true);
//Assign new location
$city = $location_json['city'];
$country = $location_json['country'];
/* Getting WeatherInfo using location from above */
$url="http://api.openweathermap.org/data/2.5/weather?q=$city,$country&units=metric&cnt=7&lang=en";
$json=file_get_contents($url);
$data=json_decode($json,true);
if($url)
{
echo $json;
}
/*Get current Temperature in Celsius
echo $data['main']['temp']."<br>";
echo $data['main']['temp_min']."<br>";
//Get weather condition
echo $data['weather'][0]['main'];
//Get cloud percentage
echo $data['clouds']['all'];
//Get wind speed
echo $data['wind']['speed'];
echo $data['main']['humidity'];
*/
?>