<?php
require __DIR__ . '/../../../view/debug.php';
require __DIR__ . '/../../../locations/locations.php';

$query = $_GET['name'] ?? false;
$lat = $_GET['lat'] ?? false;
$long = $_GET['long'] ?? false;
$realm = $_GET['realm'] ?? 'all';
$maxResults = $_GET['max'] ?? false;

$matches = Locations::search($query, $realm, $maxResults, $lat, $long);

header('Content-Type: application/json');
echo json_encode($matches);
