Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a79a3d033b
Fetching contributors…

Cannot retrieve contributors at this time

file 36 lines (27 sloc) 1.225 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
<?php
include 'main.php';
$postdata = file_get_contents("php://input");

$user = json_decode($postdata, true);
#$user['location'] = array(-27.4675018,153.0246554);
//$user['location'][0] = lat
//$user['location'][1] = long

$toilets = array_map(function($member) use ($user) {
$member['distance'] = 1000 * getDistanceBetweenPointsNew($user['location'][0], $user['location'][1], $member['latitude'], $member['longitude']);

//smells funky
$member['park_library_centre'] = ucwords(strtolower($member['park_library_centre']));
$member['availability'] = ucwords(strtolower($member['availability']));
$member['street'] = ucwords(strtolower($member['street']));
$member['suburb'] = ucwords(strtolower($member['suburb']));
$member['toilet_name'] = ucwords(strtolower($member['toilet_name']));

return $member;

}, $toilets);

$max_distance = (10 * $user['urgency']) + 1000;

$toilets = array_filter($toilets, function($member) use ($max_distance) {
//$max_distance = ($user['urgency'] + 500) * 2;
return $member['distance'] < $max_distance;
});

usort($toilets, function($a, $b) {
return $a['distance'] - $b['distance'];
});

header('content-type: application/json');
echo json_encode(array_slice($toilets, 0, 30));
Something went wrong with that request. Please try again.