You are here

public static function ProximityTrait::convertDistance in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 src/ProximityTrait.php \Drupal\geolocation\ProximityTrait::convertDistance()

Convert to/from km.

Parameters

float|int $value: Distance value.

mixed $factor: Factor to convert by. Defaults to mile.

bool $invert: FALSE converts to, TRUE from km.

Return value

bool|float Distance in km or target.

5 calls to ProximityTrait::convertDistance()
ProximityArgument::getFormula in src/Plugin/views/argument/ProximityArgument.php
ProximityField::getValue in src/Plugin/views/field/ProximityField.php
Gets the value that's supposed to be rendered.
ProximityFilter::query in src/Plugin/views/filter/ProximityFilter.php
Add this filter to the query.
ProximityFilter::valueForm in src/Plugin/views/filter/ProximityFilter.php
Provide a simple textfield for equality
ProximityFilter::valueSubmit in src/Plugin/views/filter/ProximityFilter.php
Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data.

File

src/ProximityTrait.php, line 47

Class

ProximityTrait
Trait ProximityTrait.

Namespace

Drupal\geolocation

Code

public static function convertDistance($value, $factor = NULL, $invert = FALSE) {
  $value = (double) $value;
  if (empty($factor)) {
    $factor = self::getDistanceConversions('mi');
  }
  if (is_string($factor) && !empty(self::getDistanceConversions($factor))) {
    $factor = self::getDistanceConversions($factor);
  }
  if (is_numeric($factor)) {
    if ($invert) {
      return (double) $value / $factor;
    }
    return (double) $value * $factor;
  }
  return FALSE;
}