Browse Source

Improve place results distribution

master
Skylar Ittner 3 years ago
parent
commit
402cced258
5 changed files with 48 additions and 33 deletions
  1. 2
    2
      composer.lock
  2. 39
    21
      places.php
  3. 1
    2
      required.php
  4. 1
    1
      settings.php
  5. 5
    7
      vendor/composer/ClassLoader.php

+ 2
- 2
composer.lock View File

@@ -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",

+ 39
- 21
places.php View File

@@ -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);

$out = json_encode($geo);
if ($out == false) {
sendError("Server error.");
} else {
echo $out;
}

+ 1
- 2
required.php View File

@@ -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';

+ 1
- 1
settings.php View File

@@ -7,4 +7,4 @@ define("DB_NAME", "terrain");
define("DB_SERVER", "localhost");
define("DB_USER", "terrain");
define("DB_PASS", "");
define("DB_CHARSET", "latin1");
define("DB_CHARSET", "utf8");

+ 5
- 7
vendor/composer/ClassLoader.php View File

@@ -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;
}
}


Loading…
Cancel
Save