-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
76 lines (60 loc) · 1.72 KB
/
index.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
<?php
header('Content-Type: application/json');
$API_KEY = "";
function isWet($coordinates) {
global $API_KEY;
$coord = explode(',', $coordinates);
$lat = $coord[0];
$lng = $coord[1];
$GMAPStaticUrl = 'https://maps.googleapis.com/maps/api/staticmap?center='.$lat.','.$lng.'&style=feature:all|element:labels|visibility:off&size=5x5&maptype=roadmap&sensor=false&zoom=23&key='.$API_KEY;
$chuid = curl_init();
curl_setopt($chuid, CURLOPT_URL, $GMAPStaticUrl);
curl_setopt($chuid, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($chuid, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = trim(curl_exec($chuid));
curl_close($chuid);
$image = imagecreatefromstring($data);
ob_start();
imagepng($image);
$contents = ob_get_contents();
ob_end_clean();
$hexaColor = imagecolorat($image,0,1);
$color_tran = imagecolorsforindex($image, $hexaColor);
imagedestroy($image);
$red = $color_tran['red'];
$green = $color_tran['green'];
$blue = $color_tran['blue'];
$color = $red.','.$green.','.$blue;
if ($color == '224,224,224'){
$type = [
'error' => true,
'message' => 'Please try again.'
];
}
if ($color == '170,218,255') {
$type = [
'latitude' => (float) $lat,
'longitude' => (float) $lng,
'is_wet' => true
];
} else {
$type = [
'latitude' => (float) $lat,
'longitude' => (float) $lng,
'is_wet' => false
];
}
return $type;
}
if (isset($_GET['coordinates']) && $_GET['coordinates'] !== ''){
$coordinates = $_GET['coordinates'];
$coordinates = str_replace(" ","",$coordinates);
$response = isWet($coordinates);
} else {
$response = [
'error' => true,
'message' => 'Invalid request. Missing the \'coordinates\' parameter.'
];
}
echo json_encode($response);
?>