-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore_locator.php
29 lines (23 loc) · 1002 Bytes
/
store_locator.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
<?php
//connect to db
$oLink = mysql_pconnect("localhost","root","KNOWledge") or die("Can't connect to MySQL server!");
mysql_select_db("MediFind") or die("Can't select database!");
// Get parameters
$mlat = $_POST["lat"];
$mlng = $_POST["lng"];
$radius = $_POST["radius"];
// Search the rows in the markers table
//change 3959 to 6371 for distance in KM
$sql = sprintf("SELECT name,address,contact,lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string($mlat),
mysql_real_escape_string($mlng),
mysql_real_escape_string($mlat),
mysql_real_escape_string($radius));
$result = mysql_query($sql);
$rows = array();
while($r = mysql_fetch_assoc($result)) {
$rows[] = $r;
}
mysql_close($oLink);
echo json_encode($rows);
?>