Esempio n. 1
0
    /**
     * @param ResultInterface $result
     *
     * @return string
     */
    public function dump(ResultInterface $result)
    {
        $gpx = sprintf(<<<GPX
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx
version="1.0"
    creator="Geocoder" version="%s"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.topografix.com/GPX/1/0"
    xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">

GPX
, Geocoder::VERSION);
        if ($bounds = $result->getBounds()) {
            $gpx .= sprintf(<<<GPX
    <bounds minlat="%f" minlon="%f" maxlat="%f" maxlon="%f"/>

GPX
, $bounds['west'], $bounds['south'], $bounds['east'], $bounds['north']);
        }
        $gpx .= sprintf(<<<GPX
    <wpt lat="%.7f" lon="%.7f">
        <name><![CDATA[%s]]></name>
        <type><![CDATA[Address]]></type>
    </wpt>

GPX
, $result->getLatitude(), $result->getLongitude(), $this->formatName($result));
        $gpx .= <<<GPX
</gpx>
GPX;
        return $gpx;
    }
Esempio n. 2
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);
 }
 /**
  * @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);
 }
Esempio n. 4
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;
 }
Esempio n. 6
0
 /**
  * @param ResultInterface $result
  *
  * @return string
  */
 public function dump(ResultInterface $result)
 {
     return sprintf('POINT(%F %F)', $result->getLongitude(), $result->getLatitude());
 }