'The geographical coordinates can\'t be determined for the specified address criteria.', self::EMPTY_CONTEXT => 'Form context is empty', self::EMPTY_ADDR_FIELDS => 'Address fields is empty', self::GEO_ERROR => '%value%', ); /** @var array */ protected $_addressFields = null; function __construct($options = null) { if ($options instanceof Zend_Config) { $options = $options->toArray(); } if ($options && is_array($options)) { $this->setOptions($options); } return $this; } public function setOptions($options) { if (isset($options['options'])) { unset($options['options']); } foreach ($options as $key => $value) { $method = 'set' . ucfirst($key); if (method_exists($this, $method)) { $this->$method($value); } } return $this; } public function setAddressFields(array $fields) { $this->_addressFields = $fields; return $this; } public function getAddressFields() { return $this->_addressFields; } public function isValid($value, array $context = null) { if (!is_array($context) || empty($context)) { $this->_error(self::EMPTY_CONTEXT, $value); return false; } $fields = $this->getAddressFields(); if (!is_array($fields) || empty($fields)) { $this->_error(self::EMPTY_ADDR_FIELDS, $value); return false; } $data = []; foreach ($fields as $field) { $data[$field] = Qs_Array::get($context, $field); } array_filter($data); if (empty($data)) { return true; } $address = $data['address']; if ($data['address2']) { $address .= ', ' . $data['address2']; } $address .= ', ' . $data['city']; $address .= ', ' . $data['state'] . ' ' . $data['zip']; $geocoding = new Geocoding($address); if (!$geocoding->send()) { $this->_error(self::GEO_ERROR, $geocoding->getError()); return false; } return true; } }