Exemplo 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;
    }
 /**
  * @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);
 }