-
Notifications
You must be signed in to change notification settings - Fork 0
/
apicall.php
80 lines (53 loc) · 1.67 KB
/
apicall.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
include('config/.config.php');
// get the q parameter from URL
$q = $_REQUEST["q"];
// $arr = array("text"=>"PHP Connected");
// echo json_encode($arr);
if ($q == "homeloc") {
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'https://geolocation-db.com/json/'.$GEOCODEDB_KEY);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$response1 = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($response1)){
echo "Error";
}
else{
echo $response1;
}
}
if ($q == "cityname") {
$lat = $_REQUEST["lat"];
$lon = $_REQUEST["lon"];
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'https://api.openweathermap.org/data/2.5/find?lat='.$lat.'&lon='.$lon.'&cnt=1&appid='.$OPENWEATHERMAP_KEY);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$response2 = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($response2)){
echo "Error";
}
else{
echo $response2;
}
}
if ($q == "getweather") {
$mapclick_lat = $_REQUEST["lat"];
$mapclick_lng = $_REQUEST["lon"];
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'https://api.openweathermap.org/data/2.5/onecall?lat='.$mapclick_lat.'&lon='.$mapclick_lng.'&exclude=minutely&units=metric&appid='.$OPENWEATHERMAP_KEY);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$response3 = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($response3)){
echo "Error";
}
else{
echo $response3;
}
}
?>