Пример #1
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);
 }