You are here

protected function Random::getRandomResult in Geocoder 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/Geocoder/Provider/Random.php \Drupal\geocoder\Plugin\Geocoder\Provider\Random::getRandomResult()
  2. 7.2 src/Plugin/Geocoder/Provider/Random.php \Drupal\geocoder\Plugin\Geocoder\Provider\Random::getRandomResult()

Generate a fake random address array.

@todo [cc]: Tidi-up, document, etc.

Return value

array Return array of dta such as latitude, longitude, etc.

2 calls to Random::getRandomResult()
Random::doGeocode in src/Plugin/Geocoder/Provider/Random.php
Performs the geocoding.
Random::doReverse in src/Plugin/Geocoder/Provider/Random.php
Performs the reverse geocode.

File

src/Plugin/Geocoder/Provider/Random.php, line 94

Class

Random
Class Random.

Namespace

Drupal\geocoder\Plugin\Geocoder\Provider

Code

protected function getRandomResult() {
  $country = $this
    ->getRandomCountryInfo();
  $streetTypes = [
    'street',
    'avenue',
    'square',
    'road',
    'way',
    'drive',
    'lane',
    'place',
    'hill',
    'gardens',
    'park',
  ];
  return [
    'latitude' => mt_rand(0, 90) + mt_rand() / mt_getrandmax(),
    'longitude' => mt_rand(-180, 180) + mt_rand() / mt_getrandmax(),
    'streetName' => $this
      ->getRandomCountryInfo('name') . ' ' . $streetTypes[mt_rand(0, count($streetTypes) - 1)],
    'streetNumber' => (string) mt_rand(1, 1000),
    'postalCode' => (string) mt_rand(1, 1000),
    'locality' => sha1(mt_rand() / mt_getrandmax()),
    'country' => (string) $country['name'],
    'countryCode' => $country['code'],
  ];
}