|
|
@ -35,26 +35,39 @@ if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) {
|
|
|
|
|
|
|
|
|
|
|
|
$userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']);
|
|
|
|
$userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']);
|
|
|
|
$searchbounds = $userlocation->boundingCoordinates($radius, 'miles');
|
|
|
|
$searchbounds = $userlocation->boundingCoordinates($radius, 'miles');
|
|
|
|
|
|
|
|
// Get the points halfway between the bounds
|
|
|
|
|
|
|
|
$lathalf = abs($searchbounds[1]->getLatitudeInDegrees() - $searchbounds[0]->getLatitudeInDegrees()) / 2;
|
|
|
|
|
|
|
|
$lonhalf = abs($searchbounds[1]->getLongitudeInDegrees() - $searchbounds[0]->getLongitudeInDegrees()) / 2;
|
|
|
|
|
|
|
|
|
|
|
|
if (is_empty($VARS['names'])) {
|
|
|
|
$places1 = $database->select('places', '*', ['AND' => [
|
|
|
|
$places = $database->select('places', '*', ['AND' => [
|
|
|
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
|
|
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
|
|
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees() - $lathalf, // 0 - .5
|
|
|
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
|
|
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
|
|
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
|
|
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees() - $lonhalf], // 0 - .5
|
|
|
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()],
|
|
|
|
"LIMIT" => 50]);
|
|
|
|
"LIMIT" => 100
|
|
|
|
|
|
|
|
]);
|
|
|
|
$places2 = $database->select('places', '*', ['AND' => [
|
|
|
|
} else {
|
|
|
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees() + $lathalf, // .5 - 1
|
|
|
|
$places = $database->select('places', '*', ['AND' => [
|
|
|
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
|
|
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
|
|
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees() + $lonhalf, // .5 - 1
|
|
|
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
|
|
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()],
|
|
|
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
|
|
|
"LIMIT" => 50]);
|
|
|
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(),
|
|
|
|
|
|
|
|
'name[!]' => ''],
|
|
|
|
$places3 = $database->select('places', '*', ['AND' => [
|
|
|
|
"LIMIT" => 100
|
|
|
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
|
|
|
]);
|
|
|
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees() - $lathalf, // 0 - .5
|
|
|
|
}
|
|
|
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees() + $lonhalf, // .5 - 1
|
|
|
|
|
|
|
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()],
|
|
|
|
|
|
|
|
"LIMIT" => 50]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$places4 = $database->select('places', '*', ['AND' => [
|
|
|
|
|
|
|
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees() + $lathalf, // .5 - 1
|
|
|
|
|
|
|
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
|
|
|
|
|
|
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
|
|
|
|
|
|
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees() - $lonhalf], // 0 - .5
|
|
|
|
|
|
|
|
"LIMIT" => 50]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$places = array_merge($places1, $places2, $places3, $places4);
|
|
|
|
|
|
|
|
|
|
|
|
$geo['name'] = "Places";
|
|
|
|
$geo['name'] = "Places";
|
|
|
|
$geo['type'] = 'FeatureCollection';
|
|
|
|
$geo['type'] = 'FeatureCollection';
|
|
|
@ -71,9 +84,14 @@ foreach ($places as $place) {
|
|
|
|
],
|
|
|
|
],
|
|
|
|
"properties" => [
|
|
|
|
"properties" => [
|
|
|
|
"osm_id" => intval($place['osmid']),
|
|
|
|
"osm_id" => intval($place['osmid']),
|
|
|
|
"name" => ($place['name'] == '' ? null : $place['name']),
|
|
|
|
"name" => ($place['name'] == '' ? null : $place['name'])
|
|
|
|
"name:en" => ($place['name'] == '' ? null : $place['name'])
|
|
|
|
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo json_encode($geo);
|
|
|
|
|
|
|
|
|
|
|
|
$out = json_encode($geo);
|
|
|
|
|
|
|
|
if ($out == false) {
|
|
|
|
|
|
|
|
sendError("Server error.");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo $out;
|
|
|
|
|
|
|
|
}
|