Sulu\Bundle\LocationBundle\Geolocator\GeolocatorResponse::addLocation PHP Method

addLocation() public method

Add a location to the response.
public addLocation ( GeolocatorLocation $location )
$location GeolocatorLocation
    public function addLocation(GeolocatorLocation $location)
    {
        $this->locations[] = $location;
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function locate($query)
 {
     $request = $this->client->get($this->baseUrl, [], ['query' => ['q' => $query, 'format' => 'json', 'addressdetails' => 1]]);
     $this->client->send($request);
     $response = $request->getResponse();
     if ($response->getStatusCode() != 200) {
         throw new HttpException($response->getStatusCode(), sprintf('Server at "%s" returned HTTP "%s". Body: ', $client->getUrl(), $response->getStatusCode()));
     }
     $results = $request->getResponse()->json();
     $response = new GeolocatorResponse();
     foreach ($results as $result) {
         $location = new GeolocatorLocation();
         foreach (['setStreet' => 'road', 'setNumber' => 'house_number', 'setCode' => 'postcode', 'setTown' => 'city', 'setCountry' => 'country_code'] as $method => $key) {
             if (isset($result['address'][$key])) {
                 $location->{$method}($result['address'][$key]);
             }
         }
         $location->setId($result['place_id']);
         $location->setLongitude($result['lon']);
         $location->setLatitude($result['lat']);
         $location->setDisplayTitle($result['display_name']);
         $response->addLocation($location);
     }
     return $response;
 }
All Usage Examples Of Sulu\Bundle\LocationBundle\Geolocator\GeolocatorResponse::addLocation