You are here

public function Dummy::geocode in Geolocation Field 8

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.2 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

2 calls to Dummy::geocode()
Dummy::formProcessInput in tests/modules/geolocation_dummy_geocoder/src/Plugin/geolocation/Geocoder/Dummy.php
Process from as altered above.
Dummy::formValidateInput in tests/modules/geolocation_dummy_geocoder/src/Plugin/geolocation/Geocoder/Dummy.php
Process from as altered above.

File

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

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;
  }
}