示例#1
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     $options = new \ValueFormatters\FormatterOptions(array(GeoCoordinateFormatter::OPT_FORMAT => $parameters['format'], GeoCoordinateFormatter::OPT_DIRECTIONAL => $parameters['directional'], GeoCoordinateFormatter::OPT_PRECISION => 1 / 360000));
     $coordinateFormatter = new GeoCoordinateFormatter($options);
     $output = $coordinateFormatter->format($parameters['location']);
     return $output;
 }
 /**
  * @see ValueFormatter::format
  *
  * @since 0.1
  *
  * @param GlobeCoordinateValue $value The value to format
  *
  * @return string
  * @throws InvalidArgumentException
  */
 public function format($value)
 {
     if (!$value instanceof GlobeCoordinateValue) {
         throw new InvalidArgumentException('The GlobeCoordinateFormatter can only format instances of GlobeCoordinateValue.');
     }
     $formatter = new GeoCoordinateFormatter($this->options);
     return $formatter->formatLatLongValue($value->getLatLong(), $value->getPrecision());
 }
示例#3
0
 /**
  * @see ValueFormatter::format
  *
  * @since 0.1
  *
  * @param GlobeCoordinateValue $value The value to format
  *
  * @return string
  * @throws InvalidArgumentException
  */
 public function format($value)
 {
     if (!$value instanceof GlobeCoordinateValue) {
         throw new InvalidArgumentException('Data value type mismatch. Expected a GlobeCoordinateValue.');
     }
     $formatter = new GeoCoordinateFormatter($this->options);
     return $formatter->formatLatLongValue($value->getLatLong(), $value->getPrecision());
 }
示例#4
0
 /**
  * @since 3.0
  *
  * @param SMWDIGeoCoord $dataItem
  * @param string|null $format
  *
  * @return string|null
  */
 protected function getFormattedCoord(SMWDIGeoCoord $dataItem, $format = null)
 {
     global $smgQPCoodFormat;
     $options = new \ValueFormatters\FormatterOptions(array(GeoCoordinateFormatter::OPT_FORMAT => $format === null ? $smgQPCoodFormat : $format));
     // TODO: $smgQPCoodDirectional
     $coordinateFormatter = new GeoCoordinateFormatter($options);
     $value = new LatLongValue($dataItem->getLatitude(), $dataItem->getLongitude());
     return $coordinateFormatter->format($value);
 }
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     $destination = MapsGeoFunctions::findDestination($parameters['location']->getCoordinates(), $parameters['bearing'], $parameters['distance']);
     $options = new \ValueFormatters\FormatterOptions(array(GeoCoordinateFormatter::OPT_FORMAT => $parameters['format'], GeoCoordinateFormatter::OPT_DIRECTIONAL => $parameters['directional'], GeoCoordinateFormatter::OPT_PRECISION => 1 / 360000));
     $formatter = new GeoCoordinateFormatter($options);
     $geoCoords = new \DataValues\LatLongValue($destination['lat'], $destination['lon']);
     $output = $formatter->format($geoCoords);
     return $output;
 }
示例#6
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     /**
      * @var \DataValues\LatLongValue $coordinates
      */
     $coordinates = $parameters['location']->getCoordinates();
     $options = new \ValueFormatters\FormatterOptions(array(GeoCoordinateFormatter::OPT_FORMAT => $parameters['format'], GeoCoordinateFormatter::OPT_DIRECTIONAL => $parameters['directional'], GeoCoordinateFormatter::OPT_PRECISION => 1 / 360000));
     $formatter = new GeoCoordinateFormatter($options);
     return $formatter->format($coordinates);
 }
示例#7
0
 /**
  * Geocodes an address with the provided geocoding service and returns the result 
  * as a string with the optionally provided format, or false when the geocoding failed.
  * 
  * @since 0.7
  * 
  * @param string $coordsOrAddress
  * @param string $service
  * @param string $mappingService
  * @param boolean $checkForCoords
  * @param string $targetFormat The notation to which they should be formatted. Defaults to floats.
  * @param boolean $directional Indicates if the target notation should be directional. Defaults to false.
  * 
  * @return string|false
  */
 public static function attemptToGeocodeToString($coordsOrAddress, $service = '', $mappingService = false, $checkForCoords = true, $targetFormat = Maps_COORDS_FLOAT, $directional = false)
 {
     $geoCoordinate = self::attemptToGeocode($coordsOrAddress, $service, $mappingService, $checkForCoords);
     if ($geoCoordinate === false) {
         return false;
     }
     $options = new \ValueFormatters\FormatterOptions(array(GeoCoordinateFormatter::OPT_FORMAT => $targetFormat, GeoCoordinateFormatter::OPT_DIRECTIONAL => $directional, GeoCoordinateFormatter::OPT_PRECISION => 1 / 360000));
     $formatter = new GeoCoordinateFormatter($options);
     return $formatter->format($geoCoordinate);
 }
 /**
  * @dataProvider invalidPrecisionProvider
  */
 public function testFormatLatLongValueWithInvalidPrecision_fallsBackToDefaultPrecision($precision)
 {
     $formatter = new GeoCoordinateFormatter(new FormatterOptions());
     $formatted = $formatter->formatLatLongValue(new LatLongValue(1.2, 3.4), $precision);
     $this->assertEquals('1.2, 3.4', $formatted);
 }