Exemple #1
0
    /**
     * @param Address $address
     *
     * @return string
     */
    public function dump(Address $address)
    {
        $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 ($address->getBounds()->isDefined()) {
            $bounds = $address->getBounds();
            $gpx .= sprintf(<<<GPX
    <bounds minlat="%f" minlon="%f" maxlat="%f" maxlon="%f"/>

GPX
, $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth());
        }
        $gpx .= sprintf(<<<GPX
    <wpt lat="%.7f" lon="%.7f">
        <name><![CDATA[%s]]></name>
        <type><![CDATA[Address]]></type>
    </wpt>

GPX
, $address->getLatitude(), $address->getLongitude(), $this->formatName($address));
        $gpx .= <<<GPX
</gpx>
GPX;
        return $gpx;
    }
Exemple #2
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);
 }