/** * @see StringValueParser::stringParse * * @since 3.0 * * @param string $value * * @return float * @throws ParseException */ public function stringParse($value) { $distance = \MapsDistanceParser::parseDistance($value); if ($distance === false) { throw new ParseException('Not a distance'); } return $distance; }
/** * Tests MapsDistanceParser::parseDistance() */ public function testParseDistance() { foreach (self::$distances as $rawValue => $parsedValue) { $this->assertEquals($parsedValue, MapsDistanceParser::parseDistance($rawValue), "'{$rawValue}' was not parsed to '{$parsedValue}':"); } foreach (self::$fakeDistances as $fakeDistance) { $this->assertFalse(MapsDistanceParser::parseDistance($fakeDistance), "'{$fakeDistance}' should not be recognized:"); } }
/** * @param SMWDataItem $areaCenter * @param string $comparator * @param string $radius * @param SMWDIProperty $property * * @throws InvalidArgumentException */ public function __construct(SMWDataItem $areaCenter, $comparator, $radius, SMWDIProperty $property = null) { if (!$areaCenter instanceof SMWDIGeoCoord) { throw new InvalidArgumentException('$areaCenter needs to be a SMWDIGeoCoord'); } parent::__construct($areaCenter, $property, $comparator); $this->radius = MapsDistanceParser::parseDistance($radius); $this->center = $areaCenter; $this->bounds = $this->getBoundingBox(); }
/** * Renders and returns the output. * @see ParserHook::render * * @since 0.7 * * @param array $parameters * * @return string */ public function render(array $parameters) { $distanceInMeters = MapsDistanceParser::parseDistance($parameters['distance']); return MapsDistanceParser::formatDistance($distanceInMeters, $parameters['unit'], $parameters['decimals']); }
/** * Renders and returns the output. * @see ParserHook::render * * @since 0.7 * * @param array $parameters * * @return string */ public function render(array $parameters) { $canGeocode = MapsGeocoders::canGeocode(); if ($canGeocode) { $location = MapsGeocoders::attemptToGeocode($parameters['location'], $parameters['geoservice'], $parameters['mappingservice']); } else { $location = MapsCoordinateParser::parseCoordinates($parameters['location']); } // TODO if ($location) { $destination = MapsGeoFunctions::findDestination($location, $parameters['bearing'], MapsDistanceParser::parseDistance($parameters['distance'])); $output = MapsCoordinateParser::formatCoordinates($destination, $parameters['format'], $parameters['directional']); } else { // The location should be valid when this method gets called. throw new MWException('Attempt to find a destination from an invalid location'); } return $output; }
/** * Sets the bounds fields to an array returned by SMAreaValueDescription::getBoundingBox. * * @since 0.6 * * @param SMWDIGeoCoord $dataItem * @param string $radius */ protected function calculateBounds(SMWDIGeoCoord $dataItem, $radius) { $this->bounds = self::getBoundingBox(array('lat' => $dataItem->getLatitude(), 'lon' => $dataItem->getLongitude()), MapsDistanceParser::parseDistance($radius)); }