Improve place results distribution
This commit is contained in:
parent
633ee1bf41
commit
402cced258
4
composer.lock
generated
4
composer.lock
generated
@ -4,8 +4,8 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "3263d618bf8cadc450b356bb7e55fc47",
|
"hash": "3b0bd4af5107055b045859148b17d597",
|
||||||
"content-hash": "4d7fd8e97f1d509497db70232de37ec8",
|
"content-hash": "99a4ccfc150be99d7e9c9f39f7a987b9",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "anthonymartin/geo-location",
|
"name": "anthonymartin/geo-location",
|
||||||
|
48
places.php
48
places.php
@ -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(),
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees() - $lathalf, // 0 - .5
|
||||||
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
||||||
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees() - $lonhalf], // 0 - .5
|
||||||
|
"LIMIT" => 50]);
|
||||||
|
|
||||||
|
$places2 = $database->select('places', '*', ['AND' => [
|
||||||
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees() + $lathalf, // .5 - 1
|
||||||
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
||||||
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees() + $lonhalf, // .5 - 1
|
||||||
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()],
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()],
|
||||||
"LIMIT" => 100
|
"LIMIT" => 50]);
|
||||||
]);
|
|
||||||
} else {
|
$places3 = $database->select('places', '*', ['AND' => [
|
||||||
$places = $database->select('places', '*', ['AND' => [
|
|
||||||
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
'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(),
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
||||||
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
||||||
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(),
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees() - $lonhalf], // 0 - .5
|
||||||
'name[!]' => ''],
|
"LIMIT" => 50]);
|
||||||
"LIMIT" => 100
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$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;
|
||||||
|
}
|
@ -6,8 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
header("Access-Control-Allow-Origin: *");
|
header("Access-Control-Allow-Origin: *");
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
|
|
||||||
// Composer
|
// Composer
|
||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
|
@ -7,4 +7,4 @@ define("DB_NAME", "terrain");
|
|||||||
define("DB_SERVER", "localhost");
|
define("DB_SERVER", "localhost");
|
||||||
define("DB_USER", "terrain");
|
define("DB_USER", "terrain");
|
||||||
define("DB_PASS", "");
|
define("DB_PASS", "");
|
||||||
define("DB_CHARSET", "latin1");
|
define("DB_CHARSET", "utf8");
|
12
vendor/composer/ClassLoader.php
vendored
12
vendor/composer/ClassLoader.php
vendored
@ -53,8 +53,8 @@ class ClassLoader
|
|||||||
|
|
||||||
private $useIncludePath = false;
|
private $useIncludePath = false;
|
||||||
private $classMap = array();
|
private $classMap = array();
|
||||||
|
|
||||||
private $classMapAuthoritative = false;
|
private $classMapAuthoritative = false;
|
||||||
private $missingClasses = array();
|
|
||||||
|
|
||||||
public function getPrefixes()
|
public function getPrefixes()
|
||||||
{
|
{
|
||||||
@ -322,20 +322,20 @@ class ClassLoader
|
|||||||
if (isset($this->classMap[$class])) {
|
if (isset($this->classMap[$class])) {
|
||||||
return $this->classMap[$class];
|
return $this->classMap[$class];
|
||||||
}
|
}
|
||||||
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
|
if ($this->classMapAuthoritative) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $this->findFileWithExtension($class, '.php');
|
$file = $this->findFileWithExtension($class, '.php');
|
||||||
|
|
||||||
// Search for Hack files if we are running on HHVM
|
// Search for Hack files if we are running on HHVM
|
||||||
if (false === $file && defined('HHVM_VERSION')) {
|
if ($file === null && defined('HHVM_VERSION')) {
|
||||||
$file = $this->findFileWithExtension($class, '.hh');
|
$file = $this->findFileWithExtension($class, '.hh');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false === $file) {
|
if ($file === null) {
|
||||||
// Remember that this class does not exist.
|
// Remember that this class does not exist.
|
||||||
$this->missingClasses[$class] = true;
|
return $this->classMap[$class] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $file;
|
return $file;
|
||||||
@ -399,8 +399,6 @@ class ClassLoader
|
|||||||
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
|
||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user