-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_places_nearby.php
More file actions
69 lines (54 loc) · 1.91 KB
/
get_places_nearby.php
File metadata and controls
69 lines (54 loc) · 1.91 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
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php header('content-type: application/json; charset=utf-8');
/*
* Following code will list all the places
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
if (isset($_GET["lat"]) && isset($_GET["lng"])) {
$lat = $_GET['lat'];
$lng = $_GET['lng'];
if(isset($_GET["max"])) $max = $_GET['max']; else $max = 50;
// get a places from placess table
$result = mysql_query("SELECT ID,title,address,city,latitude,longitude,category, ( 6371 * acos( cos( radians(".$lat.") ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(".$lng.") ) + sin( radians(".$lat.") ) * sin( radians( latitude ) ) ) ) AS distance FROM monumenten HAVING distance < 30000
ORDER BY distance ASC LIMIT 0,".$max."");
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// places node
$response["success"] = 1;
$response["places"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$places = array();
$places["ID"] = $row["ID"];
$places["title"] = $row["title"];
$places["address"] = $row["address"];
$places["city"] = $row["city"];
$places["latitude"] = $row["latitude"];
$places["longitude"] = $row["longitude"];
$places["category"] = $row["category"];
// push single places into final response array
array_push($response["places"], $places);
}
// success
// echoing JSON response
echo json_encode($response);
} else {
// no places found
$response["success"] = 0;
$response["message"] = "No places found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no places found
$response["success"] = 0;
$response["message"] = "No places found";
// echo no users JSON
echo json_encode($response);
}
?>