-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_location_data.php
104 lines (97 loc) · 3.05 KB
/
get_location_data.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* Created by PhpStorm.
* User: sid
* Date: 9/5/15
* Time: 7:30 AM
*/
class MapDataPoint {
public $type;
public $lat;
public $lng;
public $id;
/**
* MapDataPoint constructor.
* @param $type
* @param $lat
* @param $long
* @param $id
*/
public function __construct($type, $lat, $lng, $id) {
$this->type = $type;
$this->lat = $lat;
$this->lng = $lng;
$this->id = $id;
}
/**
* @return mixed
*/
public function getType() {
return $this->type;
}
/**
* @return mixed
*/
public function getLat() {
return $this->lat;
}
/**
* @return mixed
*/
public function getLong() {
return $this->long;
}
public function getId() {
return $this->id;
}
public function setType($newtype){
if($newtype === "group" || $newtype === "user"){
$this->type = $newtype;
}
}
}
session_start();
$servername = "us-cdbr-azure-east-b.cloudapp.net";
$username = "b0e812d8bf4e3e";
$password = "124f7801";
if(!isset($_SESSION['id']) || $_SESSION['loggedin'] === false){
header("Location: login.html");
die();
}
try{
$conn = new PDO("mysql:host=$servername;dbname=complaydb", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$minlat = $_POST['minlat'];
$maxlat = $_POST['maxlat'];
$minlong = $_POST['minlong'];
$maxlong = $_POST['maxlong'];
$get_locations = $conn->prepare("SELECT userid, X(location), Y(location) FROM users WHERE X(location) BETWEEN :minlat AND :maxlat AND Y(location) BETWEEN :minlong AND :maxlong");
$get_locations->bindParam(":minlat", $minlat);
$get_locations->bindParam(":maxlat", $maxlat);
$get_locations->bindParam(":minlong", $minlong);
$get_locations->bindParam(":maxlong", $maxlong);
$get_locations->execute();
$get_locations->setFetchMode(PDO::FETCH_ASSOC);
$results = $get_locations->fetchAll();
$mappoints = [];
foreach($results as $row){
$mappoints[] = new MapDataPoint("user", $row['X(location)'], $row['Y(location)'], $row['userid']);
}
$get_group_locations = $conn->prepare("SELECT groupid, X(location), Y(location), expirytime FROM groups WHERE X(location) BETWEEN :minlat AND :maxlat AND Y(location) BETWEEN :minlong AND :maxlong");
$get_group_locations->bindParam(":minlat", $minlat);
$get_group_locations->bindParam(":maxlat", $maxlat);
$get_group_locations->bindParam(":minlong", $minlong);
$get_group_locations->bindParam(":maxlong", $maxlong);
$get_group_locations->execute();
$get_group_locations->setFetchMode(PDO::FETCH_ASSOC);
$results = $get_group_locations->fetchAll();
error_log(count($results));
foreach($results as $row){
$mappoints[] = new MapDataPoint("group", $row['X(location)'], $row['Y(location)'], $row['groupid']);
}
echo json_encode($mappoints);
} catch(PDOException $e){
echo "Connection failed: " . $e->getMessage();
}
?>