-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.php
43 lines (35 loc) · 903 Bytes
/
location.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
<?php
require_once("connect.php")
$query = "SELECT Latitude,Longitude from donor";
$result = mysqli_query($db, $query);
//JavaScript Latitude and Longitude
// var latitude = [];
// var longitude = [];
// var coordinates = [];
$coords = array();
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$coords[] = $row;
}
$lat = $_GET["Lat"];
$longi = $_GET["Long"];
$min = 10000000;
$index = 0;
for($i=0; $i<4; $i++){
$x = $coords[$i]["Latitude"];
$y = $coords[$i]["Longitude"];
$dis = sqrt(pow(($lat-$x),2)+pow(($longi-$y),2));
if($dis<$min)
{
$min = $dis;
$index = $i;
}
}
print $coords[$index]["Latitude"];
print $coords[$index]["Longitude"];
} else {
echo "Jhol hain";
}
mysqli_close($db);
?>