diff --git a/composer.json b/composer.json index df108cf..9bd838b 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,15 @@ { - "name": "vendor/g-i-s-a-p-i", - "description": "Description of project GIS API.", + "name": "netsyms/gis-api", + "description": "Simple PHP API for accessing earth data.", "authors": [ { - "name": "skylar", - "email": "your@email.here" + "name": "Skylar Ittner", + "email": "admin@netsyms.com", + "homepage": "https://netsyms.com" } ], "require": { - "catfan/medoo": "^1.1" + "catfan/medoo": "^1.1", + "anthonymartin/geo-location": "^1.0" } } diff --git a/composer.lock b/composer.lock index 44311ef..2f19f2a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,54 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "14739f64042726cd1da2fc3588dd655d", - "content-hash": "a04c7422846ed42285920bcc09babfd3", + "hash": "3263d618bf8cadc450b356bb7e55fc47", + "content-hash": "4d7fd8e97f1d509497db70232de37ec8", "packages": [ + { + "name": "anthonymartin/geo-location", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/anthonymartin/GeoLocation.php.git", + "reference": "50bf026f069296dfae11aa195d987854b2e75855" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/anthonymartin/GeoLocation.php/zipball/50bf026f069296dfae11aa195d987854b2e75855", + "reference": "50bf026f069296dfae11aa195d987854b2e75855", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "class", + "autoload": { + "psr-0": { + "AnthonyMartin": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "CC 3.0" + ], + "authors": [ + { + "name": "Anthony Martin", + "email": "anthony@replaycreative.com", + "homepage": "http://replaycreative.com", + "role": "Developer" + } + ], + "description": "Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php", + "homepage": "https://github.com/anthonymartin/GeoLocation.php", + "keywords": [ + "bounding coordinates", + "distances", + "geocoding", + "geolocation" + ], + "time": "2016-09-17 18:05:14" + }, { "name": "catfan/medoo", "version": "v1.1.3", diff --git a/places.php b/places.php new file mode 100644 index 0000000..cb4add3 --- /dev/null +++ b/places.php @@ -0,0 +1,79 @@ +boundingCoordinates($radius, 'miles'); + +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 + ]); +} + + +$geo['name'] = "Places"; +$geo['type'] = 'FeatureCollection'; +$geo['features'] = []; + +foreach ($places as $place) { + $geo['features'][] = array("type" => "Feature", + "geometry" => [ + "type" => "Point", + "coordinates" => [ + floatval($place['longitude']), + floatval($place['latitude']) + ] + ], + "properties" => [ + "osm_id" => intval($place['osmid']), + "name" => ($place['name'] == '' ? null : $place['name']), + "name:en" => ($place['name'] == '' ? null : $place['name']) + ] + ); +} +echo json_encode($geo); \ No newline at end of file diff --git a/terrain.php b/terrain.php index d106cc1..49e999c 100644 --- a/terrain.php +++ b/terrain.php @@ -2,6 +2,8 @@ require 'required.php'; +use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation; + // Validate input if (is_empty($VARS['lat']) || is_empty($VARS['long'])) { sendError("Missing information.", true); @@ -21,21 +23,20 @@ if (abs($lat) > 90.00 || abs($long) > 180.00) { sendError("Coordinates out-of-bounds. Are you sure you're on Earth?", true); } +$userlocation = GeoLocation::fromDegrees($lat, $long); +$searchbounds = $userlocation->boundingCoordinates(1.2, 'km'); + $finallat = $lat; $finallong = $long; $failtowater = false; -if ($database->has('terrain', ["AND" => ["latitude" => $lat, "longitude" => $long]])) { - // We're good -} else if ($database->has('terrain', ["AND" => ["latitude" => $lat + .01, "longitude" => $long]])) { - $finallat = $lat + 0.01; -} else if ($database->has('terrain', ["AND" => ["latitude" => $lat, "longitude" => $long + .01]])) { - $finallong = $long + 0.01; -/*} else if ($database->has('terrain', ["AND" => ["latitude" => $lat + .01, "longitude" => $long + .01]])) { - $finallat = $finallat + 0.01; - $finallong = $finallong + 0.01;*/ -} else { +if (!$database->has('terrain', ['AND' => [ + 'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(), + 'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(), + 'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(), + 'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()] + ])) { $failtowater = true; } @@ -59,7 +60,12 @@ $terrainstrings = [ if ($failtowater) { $terrainid = 0; } else { - $terrainid = (int) $database->select('terrain', 'type', ["AND" => ["latitude" => $finallat, "longitude" => $finallong]])[0]; + $terrainid = (int) $database->select('terrain', 'type', ['AND' => [ + 'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(), + 'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(), + 'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(), + 'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()] + ])[0]; if ($terrainid == 14) { $terrainid = 13; } diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index ff6ecfb..ac67d30 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) { + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { return false; } $file = $this->findFileWithExtension($class, '.php'); // Search for Hack files if we are running on HHVM - if ($file === null && defined('HHVM_VERSION')) { + if (false === $file && defined('HHVM_VERSION')) { $file = $this->findFileWithExtension($class, '.hh'); } - if ($file === null) { + if (false === $file) { // Remember that this class does not exist. - return $this->classMap[$class] = false; + $this->missingClasses[$class] = true; } return $file; @@ -399,6 +399,8 @@ class ClassLoader if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { return $file; } + + return false; } } diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php index b7fc012..58d20bd 100644 --- a/vendor/composer/autoload_namespaces.php +++ b/vendor/composer/autoload_namespaces.php @@ -6,4 +6,5 @@ $vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname($vendorDir); return array( + 'AnthonyMartin' => array($vendorDir . '/anthonymartin/geo-location/src'), ); diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 7cf9e96..1b6ff55 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -10,9 +10,20 @@ class ComposerStaticInitced6a9042f97dd8b342a978ca0b1aac0 'c7359326b6707d98bdc176bf9ddeaebf' => __DIR__ . '/..' . '/catfan/medoo/medoo.php', ); + public static $prefixesPsr0 = array ( + 'A' => + array ( + 'AnthonyMartin' => + array ( + 0 => __DIR__ . '/..' . '/anthonymartin/geo-location/src', + ), + ), + ); + public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { + $loader->prefixesPsr0 = ComposerStaticInitced6a9042f97dd8b342a978ca0b1aac0::$prefixesPsr0; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index f96b005..a7439b7 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -55,5 +55,52 @@ "sql", "sqlite" ] + }, + { + "name": "anthonymartin/geo-location", + "version": "v1.0.1", + "version_normalized": "1.0.1.0", + "source": { + "type": "git", + "url": "https://github.com/anthonymartin/GeoLocation.php.git", + "reference": "50bf026f069296dfae11aa195d987854b2e75855" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/anthonymartin/GeoLocation.php/zipball/50bf026f069296dfae11aa195d987854b2e75855", + "reference": "50bf026f069296dfae11aa195d987854b2e75855", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "time": "2016-09-17 18:05:14", + "type": "class", + "installation-source": "dist", + "autoload": { + "psr-0": { + "AnthonyMartin": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "CC 3.0" + ], + "authors": [ + { + "name": "Anthony Martin", + "email": "anthony@replaycreative.com", + "homepage": "http://replaycreative.com", + "role": "Developer" + } + ], + "description": "Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php", + "homepage": "https://github.com/anthonymartin/GeoLocation.php", + "keywords": [ + "bounding coordinates", + "distances", + "geocoding", + "geolocation" + ] } ]