You are here

public function Dummy::geocode in Geolocation Field 8.2

Same name and namespace in other branches
  1. 8.3 tests/modules/geolocation_dummy_geocoder/src/Plugin/geolocation/Geocoder/Dummy.php \Drupal\geolocation_dummy_geocoder\Plugin\geolocation\Geocoder\Dummy::geocode()
  2. 8 tests/modules/geolocation_dummy_geocoder/src/Plugin/geolocation/Geocoder/Dummy.php \Drupal\geolocation_dummy_geocoder\Plugin\geolocation\Geocoder\Dummy::geocode()

Geocode an address.

Parameters

string $address: Address to geocode.

Return value

array||null Location or NULL.

Overrides GeocoderBase::geocode

File

tests/modules/geolocation_dummy_geocoder/src/Plugin/geolocation/Geocoder/Dummy.php, line 74

Class

Dummy
Provides the Google Geocoding API.

Namespace

Drupal\geolocation_dummy_geocoder\Plugin\geolocation\Geocoder

Code

public function geocode($address) {
  if (empty($address)) {
    return FALSE;
  }
  if (!empty(self::$targets[$address])) {
    return [
      'location' => [
        'lat' => self::$targets[$address]['lat'],
        'lng' => self::$targets[$address]['lng'],
      ],
      'boundary' => [
        'lat_north_east' => self::$targets[$address]['lat'] + 0.01,
        'lng_north_east' => self::$targets[$address]['lng'] + 0.01,
        'lat_south_west' => self::$targets[$address]['lat'] + 0.01,
        'lng_south_west' => self::$targets[$address]['lng'] + 0.01,
      ],
    ];
  }
  else {
    return FALSE;
  }
}