Пример #1
0
 /**
  * @param Address $address
  *
  * @return string
  */
 protected function formatName(Address $address)
 {
     $name = [];
     $array = $address->toArray();
     $attrs = [['streetNumber'], ['streetName'], ['postalCode'], ['locality'], ['adminLevels', 2, 'name'], ['adminLevels', 1, 'name'], ['country']];
     foreach ($attrs as $attr) {
         $name[] = \igorw\get_in($array, $attr);
     }
     return implode(', ', array_filter($name));
 }
 public static function mapRenderer(Address $address)
 {
     static::setContentType('text/html');
     $formatter = new \Geocoder\Formatter\StringFormatter();
     $latitude = $address->getLatitude();
     $longitude = $address->getLongitude();
     $title = $formatter->format($address, "%L, %S, %n");
     $body = "\n\t\t\t<iframe \n\t\t\t\tframeborder='0'\n\t\t\t\tscrolling='no' \n\t\t\t\tmarginheight='0'\n\t\t\t\tmarginwidth='0'\n\t\t\t\twidth='300' \n\t\t\t\theight='300' \n\t\t\t\tsrc='https://maps.google.com/maps?hl=en&q={$latitude}, {$longitude}&ie=UTF8&t=m&z=19&iwloc=B&output=embed'>\n\t\t\t</iframe>\t\n\t\t";
     return static::htmlSerializer($body, static::$htmlMetadata, $title, null, self::GoogleAnalyticsSnippet(), true);
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 public function dump(Address $address)
 {
     $values = array();
     foreach ($address->toArray() as $key => $value) {
         if (!is_array($value)) {
             $values[$key] = $value;
         }
     }
     unset($values['latitude']);
     unset($values['longitude']);
     return implode(',', array_filter($values));
 }
Пример #4
0
 /**
  * Transform an `Address` instance into a string representation.
  *
  * @param Address $address
  * @param string  $format
  *
  * @return string
  */
 public function format(Address $address, $format)
 {
     $replace = [self::STREET_NUMBER => $address->getStreetNumber(), self::STREET_NAME => $address->getStreetName(), self::LOCALITY => $address->getLocality(), self::POSTAL_CODE => $address->getPostalCode(), self::SUB_LOCALITY => $address->getSubLocality(), self::COUNTRY => $address->getCountry()->getName(), self::COUNTRY_CODE => $address->getCountry()->getCode(), self::TIMEZONE => $address->getTimezone()];
     for ($level = 1; $level <= AdminLevelCollection::MAX_LEVEL_DEPTH; $level++) {
         $replace[self::ADMIN_LEVEL . $level] = null;
         $replace[self::ADMIN_LEVEL_CODE . $level] = null;
     }
     foreach ($address->getAdminLevels() as $level => $adminLevel) {
         $replace[self::ADMIN_LEVEL . $level] = $adminLevel->getName();
         $replace[self::ADMIN_LEVEL_CODE . $level] = $adminLevel->getCode();
     }
     return strtr($format, $replace);
 }
Пример #5
0
 /**
  * Set the latitude and the longitude of the coordinates into an selected ellipsoid.
  *
  * @param Address|array|string         $coordinates The coordinates.
  * @param Ellipsoid                    $ellipsoid   The selected ellipsoid (WGS84 by default).
  *
  * @throws InvalidArgumentException
  */
 public function __construct($coordinates, Ellipsoid $ellipsoid = null)
 {
     if ($coordinates instanceof Address) {
         $this->setLatitude($coordinates->getLatitude());
         $this->setLongitude($coordinates->getLongitude());
     } elseif (is_array($coordinates) && 2 === count($coordinates)) {
         $this->setLatitude($coordinates[0]);
         $this->setLongitude($coordinates[1]);
     } elseif (is_string($coordinates)) {
         $this->setFromString($coordinates);
     } else {
         throw new InvalidArgumentException('It should be a string, an array or a class which implements Geocoder\\Model\\Address !');
     }
     $this->ellipsoid = $ellipsoid ?: Ellipsoid::createFromName(Ellipsoid::WGS84);
 }
Пример #6
0
 /**
  * Returns the longitude value.
  *
  * @return double
  */
 public function getLongitude()
 {
     if (null === $this->address) {
         return null;
     }
     return $this->address->getLongitude();
 }
Пример #7
0
 /**
  * {@inheritDoc}
  */
 public function dump(Address $address)
 {
     $properties = array_filter($address->toArray(), function ($value) {
         return !empty($value);
     });
     unset($properties['latitude'], $properties['longitude'], $properties['bounds']);
     if (0 === count($properties)) {
         $properties = null;
     }
     $json = ['type' => 'Feature', 'geometry' => ['type' => 'Point', 'coordinates' => [$address->getLongitude(), $address->getLatitude()]], 'properties' => $properties];
     if (null !== ($bounds = $address->getBounds())) {
         if ($bounds->isDefined()) {
             $json['bounds'] = $bounds->toArray();
         }
     }
     return json_encode($json);
 }
Пример #8
0
 protected function compareNumbers(Address $a, Address $b, $query)
 {
     // if one of the addresses doesn't even have a number in it,
     $aNumber = UserInputHelpers::normalizeNumber($a->getStreetNumber());
     $bNumber = UserInputHelpers::normalizeNumber($b->getStreetNumber());
     if ($aNumber && !$bNumber) {
         return -1;
     }
     if ($bNumber && !$aNumber) {
         return 1;
     }
     if (!($inputNumber = UserInputHelpers::matchStreet($query))) {
         return 0;
     }
     if ($this->isNumberFull($inputNumber)) {
         // preffer more exact
         $aEquals = $this->equalsNumber($aNumber, $inputNumber);
         $bEquals = $this->equalsNumber($bNumber, $inputNumber);
         if ($aEquals && !$bEquals) {
             return -1;
         }
         if ($bEquals && !$aEquals) {
             return 1;
         }
     }
     // preffer more data, but at least one component must equal
     $aPartially = $this->equalsNumberPartially($aNumber, $inputNumber);
     $bPartially = $this->equalsNumberPartially($bNumber, $inputNumber);
     if ($aPartially && !$bPartially) {
         return -1;
     }
     if ($bPartially && !$aPartially) {
         return 1;
     }
     $aHasMore = $this->isNumberFull($aNumber) && !$this->isNumberFull($bNumber);
     $bHasMore = $this->isNumberFull($bNumber) && !$this->isNumberFull($aNumber);
     if ($aHasMore && !$bHasMore) {
         return -1;
     }
     if ($bHasMore && !$aHasMore) {
         return 1;
     }
     return 0;
 }
Пример #9
0
 public static function format(Address $address, $options)
 {
     $data = array_filter(['country' => $address->getCountry()->getName(), 'city' => $address->getLocality(), 'district' => $address->getSubLocality(), 'postalCode' => $address->getPostalCode(), 'streetName' => $address->getStreetName(), 'streetNumber' => $address->getStreetNumber()]);
     if ($options['format'] === self::FORMAT_REVERSED) {
         $data = array_reverse($data);
     }
     if ($options['type'] === self::TYPE_SHORT) {
         unset($data['country']);
     }
     return implode(', ', $data);
 }
Пример #10
0
 public function insertUserInformation($ipAddress, $userAgentString, $sapiName, GeocoderResult $geocoderResult = null)
 {
     $userAgent = new UserAgent();
     $userAgent->setUserAgent($userAgentString);
     $browser = $userAgent->browser();
     $platform = $userAgent->platform();
     $data = ['ip_address' => $ipAddress, 'sapi_name' => substr($sapiName, 0, 32), 'user_agent' => substr($userAgentString, 0, 255), 'user_agent_browser' => substr($browser, 0, 32), 'user_agent_device' => substr($userAgent->device(), 0, 32), 'user_agent_browser_version' => substr($userAgent->version($browser), 0, 32), 'user_agent_platform_version' => substr($userAgent->version($platform), 0, 32), 'user_agent_platform' => substr($platform, 0, 32), 'user_agent_robot' => substr($userAgent->robot(), 0, 32)];
     if ($geocoderResult) {
         $region = $geocoderResult->getAdminLevels()->first();
         $data['geo_city'] = substr($geocoderResult->getLocality(), 0, 32);
         $data['geo_region'] = $region ? substr($region->getCode(), 0, 32) : null;
         $data['geo_country'] = substr($geocoderResult->getCountry(), 0, 32);
         $data['geo_country_code'] = substr($geocoderResult->getCountryCode(), 0, 6);
         $data['geo_latitude'] = substr($geocoderResult->getLatitude(), 0, 32);
         $data['geo_longitude'] = substr($geocoderResult->getLongitude(), 0, 32);
     }
     $this->getAdapter()->insert('dewdrop_activity_log_user_information', $data);
     return $this->getAdapter()->lastInsertId();
 }
Пример #11
0
 /**
  * {@inheritDoc}
  */
 public function dump(Address $address)
 {
     return pack('cLdd', 1, 1, $address->getLongitude(), $address->getLatitude());
 }
Пример #12
0
 /**
  * {@inheritDoc}
  */
 public function dump(Address $address)
 {
     return sprintf('POINT(%F %F)', $address->getLongitude(), $address->getLatitude());
 }
Пример #13
0
 /**
  * @param Address $address
  * @param string $geocoderQuery
  * @return boolean
  */
 private function queryContainsCity(Address $address, $geocoderQuery)
 {
     return Strings::match($geocoderQuery, '~(\\s|-|,|^)' . preg_quote($address->getLocality()) . '(\\s|-|,|\\z)~');
 }
Пример #14
0
 /**
  * Set postal code
  *
  * @param \Geocoder\Model\Address $address
  * @return Geo
  */
 private function setPostalCode($address)
 {
     $this->postalCode = $address->getPostalCode();
     return $this;
 }
Пример #15
0
 private function formatStreet(Address $address)
 {
     return $address->getStreetName() . ($address->getStreetNumber() ? ' ' . $address->getStreetNumber() : '');
 }
Пример #16
0
 /**
  * Expects certain address types to be present in the given address.
  *
  * @param \Geocoder\Model\Address $address
  * @return bool
  */
 public function isExpectedType(Address $address)
 {
     $expected = $this->_config['expect'];
     if (!$expected) {
         return true;
     }
     $adminLevels = $address->getAdminLevels();
     $map = [static::TYPE_AAL1 => 1, static::TYPE_AAL2 => 2, static::TYPE_AAL3 => 3, static::TYPE_AAL4 => 4, static::TYPE_AAL5 => 5];
     foreach ($expected as $expect) {
         switch ($expect) {
             case static::TYPE_COUNTRY:
                 if ($address->getCountry() !== null) {
                     return true;
                 }
                 break;
             case static::TYPE_AAL1:
             case static::TYPE_AAL2:
             case static::TYPE_AAL3:
             case static::TYPE_AAL4:
             case static::TYPE_AAL5:
                 if ($adminLevels->has($map[$expect])) {
                     return true;
                 }
                 break;
             case static::TYPE_LOC:
                 if ($address->getLocality() !== null) {
                     return true;
                 }
                 break;
             case static::TYPE_SUBLOC:
                 if ($address->getSubLocality() !== null) {
                     return true;
                 }
                 break;
             case static::TYPE_POSTAL:
                 if ($address->getPostalCode() !== null) {
                     return true;
                 }
                 break;
             case static::TYPE_ADDRESS:
                 if ($address->getStreetName() !== null) {
                     return true;
                 }
                 break;
             case static::TYPE_NUMBER:
                 if ($address->getStreetNumber() !== null) {
                     return true;
                 }
                 break;
         }
     }
     return false;
 }