/** * Returns a new Latitude object * * @param $value * @throws InvalidNativeArgumentException */ public function __construct($value) { $value = \filter_var($value, FILTER_VALIDATE_FLOAT); if (false === $value) { throw new InvalidNativeArgumentException($value, array('float')); } // normalization process through Coordinate object $coordinate = new BaseCoordinate(array($value, 0)); $latitude = $coordinate->getLatitude(); $this->value = $latitude; }
protected function execute(InputInterface $input, OutputInterface $output) { $coordinate = new Coordinate($input->getArgument('coordinate')); $geocoder = new ProviderAggregator(); $adapter = $this->getAdapter($input->getOption('adapter')); $provider = $this->getProvider($input->getOption('provider')); if ($input->getOption('args')) { $args = is_array($input->getOption('args')) ? implode(',', $input->getOption('args')) : $input->getOption('args'); $geocoder->registerProvider(new $provider(new $adapter(), $args)); } else { $geocoder->registerProvider(new $provider(new $adapter())); } $reversed = $geocoder->reverse($coordinate->getLatitude(), $coordinate->getLongitude()); $reversed = $reversed->first(); $formatter = new Formatter(); if ($input->getOption('raw')) { $result = array(); $result[] = sprintf('<label>Adapter</label>: <value>%s</value>', $adapter); $result[] = sprintf('<label>Provider</label>: <value>%s</value>', $provider); if ($input->getOption('args')) { $result[] = sprintf('<label>Arguments</label>: <value>%s</value>', $args); } $result[] = '---'; $result[] = sprintf('<label>Latitude</label>: <value>%s</value>', $reversed->getLatitude()); $result[] = sprintf('<label>Longitude</label>: <value>%s</value>', $reversed->getLongitude()); if (null !== ($bounds = $reversed->getBounds()->toArray())) { $result[] = '<label>Bounds</label>'; $result[] = sprintf(' - <label>South</label>: <value>%s</value>', $bounds['south']); $result[] = sprintf(' - <label>West</label>: <value>%s</value>', $bounds['west']); $result[] = sprintf(' - <label>North</label>: <value>%s</value>', $bounds['north']); $result[] = sprintf(' - <label>East</label>: <value>%s</value>', $bounds['east']); } $result[] = sprintf('<label>Street Number</label>: <value>%s</value>', $reversed->getStreetNumber()); $result[] = sprintf('<label>Street Name</label>: <value>%s</value>', $reversed->getStreetName()); $result[] = sprintf('<label>Zipcode</label>: <value>%s</value>', $reversed->getPostalCode()); $result[] = sprintf('<label>City</label>: <value>%s</value>', $reversed->getLocality()); $result[] = sprintf('<label>City District</label>: <value>%s</value>', $reversed->getSubLocality()); if (NULL !== ($adminLevels = $reversed->getAdminLevels())) { $result[] = '<label>Admin Levels</label>'; foreach ($adminLevels as $adminLevel) { $result[] = sprintf(' - <label>%s</label>: <value>%s</value>', $adminLevel->getCode(), $adminLevel->getName()); } } $result[] = sprintf('<label>Country</label>: <value>%s</value>', $reversed->getCountry()->toString()); $result[] = sprintf('<label>Country Code</label>: <value>%s</value>', $reversed->getCountryCode()); $result[] = sprintf('<label>Timezone</label>: <value>%s</value>', $reversed->getTimezone()); } elseif ($input->getOption('json')) { $result = sprintf('<value>%s</value>', json_encode($reversed->toArray())); } else { $result = $formatter->format($reversed, $input->getOption('format')); } $output->writeln($result); }
/** * Returns a new Coordinate object from native PHP arguments * * @return self * @throws \BadMethodCallException */ public static function fromNative() { $args = \func_get_args(); if (\count($args) < 2 || \count($args) > 3) { throw new \BadMethodCallException('You must provide 2 to 3 arguments: 1) latitude, 2) longitude, 3) valid ellipsoid type (optional)'); } $coordinate = new BaseCoordinate(array($args[0], $args[1])); $latitude = Latitude::fromNative($coordinate->getLatitude()); $longitude = Longitude::fromNative($coordinate->getLongitude()); $nativeEllipsoid = isset($args[2]) ? $args[2] : null; $ellipsoid = Ellipsoid::fromNative($nativeEllipsoid); return new static($latitude, $longitude, $ellipsoid); }
$PDO->exec('ALTER TABLE `' . PREFIX . 'route` ADD `refactored` TINYINT UNSIGNED NOT NULL DEFAULT 0 FIRST;'); $PDO->exec('ALTER TABLE `' . PREFIX . 'route` ADD INDEX `refactored` (`refactored`);'); $PDO->exec('UPDATE `' . PREFIX . 'route` SET `lats` = NULL, `refactored` = 1 WHERE `lats` = "" OR `lats` IS NULL'); } $IsNotRefactored = true; /** * Overview for data */ $Routes = $PDO->query('SELECT id, lats, lngs, startpoint_lat, startpoint_lng, endpoint_lat, endpoint_lng, min_lat, min_lng, max_lat, max_lng FROM ' . PREFIX . 'route WHERE `refactored`=0 LIMIT ' . LIMIT); $InsertGeohash = $PDO->prepare('UPDATE ' . PREFIX . 'route SET `refactored`=1, `geohashes`=:geohash, `startpoint`=:startpoint, `endpoint`=:endpoint, `min`=:min, `max`=:max WHERE `id` = :id'); while ($Route = $Routes->fetch()) { $lats = explode("|", $Route['lats']); $lngs = explode("|", $Route['lngs']); $quantity = count($lats); $geohashArray = array(); $Coordinate = new Coordinate(array(0, 0)); for ($i = 0; $i < $quantity; $i++) { // TODO: use a persisent Geohash object as soon as that's possible, see https://github.com/thephpleague/geotools/issues/73 $Coordinate->setLatitude((double) $lats[$i]); $Coordinate->setLongitude((double) $lngs[$i]); $geohashArray[] = (new Geohash())->encode($Coordinate, 12)->getGeohash(); } $InsertGeohash->execute(array(':geohash' => implode("|", $geohashArray), ':id' => $Route['id'], ':startpoint' => (new Geohash())->encode(new Coordinate(array((double) $Route['startpoint_lat'], (double) $Route['startpoint_lng'])), 10)->getGeohash(), ':endpoint' => (new Geohash())->encode(new Coordinate(array((double) $Route['endpoint_lat'], (double) $Route['endpoint_lng'])), 10)->getGeohash(), ':min' => (new Geohash())->encode(new Coordinate(array((double) $Route['min_lat'], (double) $Route['min_lng'])), 10)->getGeohash(), ':max' => (new Geohash())->encode(new Coordinate(array((double) $Route['max_lat'], (double) $Route['max_lng'])), 10)->getGeohash())); if (CLI) { echo "[7D"; $diff = count($Route['id']); echo str_pad($Route['id'], 7 - $diff, ' ', STR_PAD_LEFT); } else { echo "."; } }
/** * Returns a boolean determining coordinates equality * @param Coordinate $coordinate * @return boolean */ public function isEqual(Coordinate $coordinate) { return bccomp($this->latitude, $coordinate->getLatitude(), $this->getPrecision()) === 0 && bccomp($this->longitude, $coordinate->getLongitude(), $this->getPrecision()) === 0; }