Пример #1
0
 /**
  * Set the latitude and the longitude of the coordinates into an selected ellipsoid.
  *
  * @param ResultInterface|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 ResultInterface) {
         $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\\Result\\ResultInterface !');
     }
     $this->ellipsoid = $ellipsoid ?: Ellipsoid::createFromName(Ellipsoid::WGS84);
 }
Пример #2
0
 /**
  * @param ResultInterface $result
  *
  * @return string
  */
 protected function formatName(ResultInterface $result)
 {
     $name = '';
     $array = $result->toArray();
     $attrs = array('streetNumber', 'streetName', 'zipcode', 'city', 'county', 'region', 'country');
     foreach ($attrs as $attr) {
         if (isset($array[$attr]) && !empty($array[$attr])) {
             $name .= sprintf('%s, ', $array[$attr]);
         }
     }
     if (strlen($name) > 1) {
         $name = substr($name, 0, strlen($name) - 2);
     }
     return $name;
 }
 /**
  * @param ResultInterface $result
  *
  * @return string
  */
 public function dump(ResultInterface $result)
 {
     $properties = array_filter($result->toArray(), function ($val) {
         return $val !== null;
     });
     unset($properties['latitude'], $properties['longitude'], $properties['bounds']);
     if (count($properties) === 0) {
         $properties = null;
     }
     $json = array('type' => 'Feature', 'geometry' => array('type' => 'Point', 'coordinates' => array($result->getLongitude(), $result->getLatitude())), 'properties' => $properties);
     // Custom bounds property
     $bounds = $result->getBounds();
     if (null !== $bounds) {
         $json['bounds'] = $bounds;
     }
     return json_encode($json);
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function format($format)
 {
     return strtr($format, array(FormatterInterface::STREET_NUMBER => $this->result->getStreetNumber(), FormatterInterface::STREET_NAME => $this->result->getStreetName(), FormatterInterface::CITY => $this->result->getCity(), FormatterInterface::ZIPCODE => $this->result->getZipcode(), FormatterInterface::CITY_DISTRICT => $this->result->getCityDistrict(), FormatterInterface::COUNTY => $this->result->getCounty(), FormatterInterface::COUNTY_CODE => $this->result->getCountyCode(), FormatterInterface::REGION => $this->result->getRegion(), FormatterInterface::REGION_CODE => $this->result->getRegionCode(), FormatterInterface::COUNTRY => $this->result->getCountry(), FormatterInterface::COUNTRY_CODE => $this->result->getCountryCode(), FormatterInterface::TIMEZONE => $this->result->getTimezone()));
 }
Пример #5
0
 /**
  * @param ResultInterface $result
  *
  * @return string
  */
 public function dump(ResultInterface $result)
 {
     return pack('cLdd', 1, 1, $result->getLongitude(), $result->getLatitude());
 }
 /**
  * @param ResultInterface $result
  *
  * @return Address
  */
 public function geocoderResultToAddress(ResultInterface $result)
 {
     $address = new Address();
     $address->setCity($result->getCity());
     $address->setCountry($result->getCountry());
     $address->setCountryCode($result->getCountryCode());
     $address->setRegion($result->getRegion());
     $address->setRegionCode($result->getRegionCode());
     $address->setCounty($result->getCounty());
     $address->setCountyCode($result->getCountyCode());
     $address->setLat($result->getLatitude());
     $address->setLng($result->getLongitude());
     $address->setPostalCode($result->getZipcode());
     $address->setStreetName($result->getStreetName());
     $address->setStreetNumber($result->getStreetNumber());
     $this->addressManager->updateFormattedAddress($address);
     return $address;
 }
Пример #7
0
 /**
  * @param ResultInterface $result
  *
  * @return string
  */
 public function dump(ResultInterface $result)
 {
     return sprintf('POINT(%F %F)', $result->getLongitude(), $result->getLatitude());
 }