-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsnappedLocation.php
More file actions
54 lines (51 loc) · 1.47 KB
/
snappedLocation.php
File metadata and controls
54 lines (51 loc) · 1.47 KB
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
<?php
/**
* Created by PhpStorm.
* User: waicung
* Date: 01/06/2016
* Time: 20:27
*/
require_once __DIR__ . '/db_config.php';
$conn=mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
$response = array();
$search_query = "SELECT l.record_id AS record_id,l.location_id,s.latitude,s.longitude FROM locations AS l
JOIN snap_to_road AS s ON l.location_id=s.matchedlocation_id
WHERE l.record_id in (
SELECT l.record_id FROM recordings
WHERE assignment_id in(
SELECT assignment_id FROM route_assignments
WHERE user_id in (
SELECT user_id FROM users
WHERE user_group = 0)))
AND s.latitude <> 0
ORDER BY l.record_id,time_stamp";
$result = mysqli_query($conn,$search_query);
// TODO: check if empty
$tag = "";
$locaions = array();
$point = array();
$record = array();
while($row = mysqli_fetch_assoc($result)){
if($tag=="" || $tag<>$row['record_id']){
if($tag==""){}
else{
$record['id'] = $tag;
$record['locations'] = $locations;
array_push($response,$record);
}
$tag = $row['record_id'];
$locations = array();
}
if($tag == $row['record_id']){
$point = array();
$point['lat'] = doubleval($row['latitude']);
$point['lng'] = doubleval($row['longitude']);
$point['location_id'] = intval($row['location_id']);
array_push($locations,$point);
}
}
$record['id'] = $tag;
$record['locations'] = $locations;
array_push($response,$record);
echo json_encode($response);
?>