You are here

protected static function GeolocationGeometryBase::getRandomCoordinates in Geolocation Field 8.3

Return a random set of latitude/longitude.

Return value

float[] Coordinates.

2 calls to GeolocationGeometryBase::getRandomCoordinates()
GeolocationGeometryBase::generateSampleValue in modules/geolocation_geometry/src/Plugin/Field/FieldType/GeolocationGeometryBase.php
Generates placeholder field values.
GeolocationGeometryPolygon::generateSampleValue in modules/geolocation_geometry/src/Plugin/Field/FieldType/GeolocationGeometryPolygon.php
Generates placeholder field values.

File

modules/geolocation_geometry/src/Plugin/Field/FieldType/GeolocationGeometryBase.php, line 157

Class

GeolocationGeometryBase
Class Geolocation Geometry Base.

Namespace

Drupal\geolocation_geometry\Plugin\Field\FieldType

Code

protected static function getRandomCoordinates(array $reference_point = NULL, int $range = 5) {
  if ($reference_point) {
    return [
      'latitude' => rand(max(-89, $reference_point['latitude'] - $range), min(90, $reference_point['latitude'] + $range)) - rand(0, 999999) / 1000000,
      'longitude' => rand(max(-179, $reference_point['longitude'] - $range), min(180, $reference_point['longitude'] + $range)) - rand(0, 999999) / 1000000,
    ];
  }
  return [
    'latitude' => rand(-89, 90) - rand(0, 999999) / 1000000,
    'longitude' => rand(-179, 180) - rand(0, 999999) / 1000000,
  ];
}