/** * 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) { if (MapsGeocoders::canGeocode()) { $start = MapsGeocoders::attemptToGeocode($parameters['location1'], $parameters['geoservice'], $parameters['mappingservice']); $end = MapsGeocoders::attemptToGeocode($parameters['location2'], $parameters['geoservice'], $parameters['mappingservice']); } else { $start = MapsCoordinateParser::parseCoordinates($parameters['location1']); $end = MapsCoordinateParser::parseCoordinates($parameters['location2']); } if ($start && $end) { $output = MapsDistanceParser::formatDistance(MapsGeoFunctions::calculateDistance($start, $end), $parameters['unit'], $parameters['decimals']); } else { // The locations should be valid when this method gets called. throw new Exception('Attempt to find the distance between locations of at least one is invalid'); } return $output; }
/** * Renders and returns the output. * @see ParserHook::render * * @since 0.7 * * @param array $parameters * * @return string * @throws MWException */ public function render(array $parameters) { /** * @var \DataValues\LatLongValue $coordinates1 * @var \DataValues\LatLongValue $coordinates2 */ $coordinates1 = $parameters['location1']->getCoordinates(); $coordinates2 = $parameters['location2']->getCoordinates(); $distance = MapsGeoFunctions::calculateDistance($coordinates1, $coordinates2); $output = MapsDistanceParser::formatDistance($distance, $parameters['unit'], $parameters['decimals']); return $output; }
/** * Tests MapsDistanceParser::formatDistance() */ public function testFormatDistance() { foreach (self::$formatTests['km'] as $rawValue => $parsedValue) { $this->assertEquals($rawValue, MapsDistanceParser::formatDistance($parsedValue, 'km'), "'{$parsedValue}' was not formatted to '{$rawValue}':"); } }