From 402cced2588cb823e76ccc220f81f4533eefc679 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 1 Nov 2016 01:58:08 -0600 Subject: [PATCH] Improve place results distribution --- composer.lock | 4 +-- places.php | 60 +++++++++++++++++++++------------ required.php | 3 +- settings.php | 2 +- vendor/composer/ClassLoader.php | 12 +++---- 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/composer.lock b/composer.lock index 2f19f2a..db1fd5d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "3263d618bf8cadc450b356bb7e55fc47", - "content-hash": "4d7fd8e97f1d509497db70232de37ec8", + "hash": "3b0bd4af5107055b045859148b17d597", + "content-hash": "99a4ccfc150be99d7e9c9f39f7a987b9", "packages": [ { "name": "anthonymartin/geo-location", diff --git a/places.php b/places.php index cb4add3..983a034 100644 --- a/places.php +++ b/places.php @@ -35,26 +35,39 @@ if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) { $userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']); $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'])) { - $places = $database->select('places', '*', ['AND' => [ - 'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(), - 'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(), - 'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(), - 'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()], - "LIMIT" => 100 - ]); -} else { - $places = $database->select('places', '*', ['AND' => [ - 'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(), - 'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(), - 'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(), - 'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(), - 'name[!]' => ''], - "LIMIT" => 100 - ]); -} +$places1 = $database->select('places', '*', ['AND' => [ + 'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(), + 'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees() - $lathalf, // 0 - .5 + '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()], + "LIMIT" => 50]); + +$places3 = $database->select('places', '*', ['AND' => [ + '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['type'] = 'FeatureCollection'; @@ -71,9 +84,14 @@ foreach ($places as $place) { ], "properties" => [ "osm_id" => intval($place['osmid']), - "name" => ($place['name'] == '' ? null : $place['name']), - "name:en" => ($place['name'] == '' ? null : $place['name']) + "name" => ($place['name'] == '' ? null : $place['name']) ] ); } -echo json_encode($geo); \ No newline at end of file + +$out = json_encode($geo); +if ($out == false) { + sendError("Server error."); +} else { + echo $out; +} \ No newline at end of file diff --git a/required.php b/required.php index dcc5620..a5a8820 100644 --- a/required.php +++ b/required.php @@ -6,8 +6,7 @@ */ header("Access-Control-Allow-Origin: *"); -header('Content-Type: application/json'); - +header('Content-Type: application/json; charset=utf-8'); // Composer require 'vendor/autoload.php'; diff --git a/settings.php b/settings.php index 1dc184d..788be0d 100644 --- a/settings.php +++ b/settings.php @@ -7,4 +7,4 @@ define("DB_NAME", "terrain"); define("DB_SERVER", "localhost"); define("DB_USER", "terrain"); define("DB_PASS", ""); -define("DB_CHARSET", "latin1"); \ No newline at end of file +define("DB_CHARSET", "utf8"); \ No newline at end of file diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index ac67d30..ff6ecfb 100644 --- a/vendor/composer/ClassLoader.php +++ b/vendor/composer/ClassLoader.php @@ -53,8 +53,8 @@ class ClassLoader private $useIncludePath = false; private $classMap = array(); + private $classMapAuthoritative = false; - private $missingClasses = array(); public function getPrefixes() { @@ -322,20 +322,20 @@ class ClassLoader if (isset($this->classMap[$class])) { return $this->classMap[$class]; } - if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + if ($this->classMapAuthoritative) { return false; } $file = $this->findFileWithExtension($class, '.php'); // 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'); } - if (false === $file) { + if ($file === null) { // Remember that this class does not exist. - $this->missingClasses[$class] = true; + return $this->classMap[$class] = false; } return $file; @@ -399,8 +399,6 @@ class ClassLoader if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { return $file; } - - return false; } }