/** * * @param \Ivory\GoogleMapBundle\Model\Services\Geocoding\Result\GeocoderResponse $response * @return array */ protected function getFirstResult(\Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse $response) { $out = array(); if ($response->getStatus() == 'OVER_QUERY_LIMIT') { throw new \Exception('STOP'); } $r = $response->getResults(); if (count($r) == 0) { throw new \Exception('No dati geolocalizzati'); } $result = $r[0]; $out['lat'] = $result->getGeometry()->getLocation()->getLatitude(); $out['lon'] = $result->getGeometry()->getLocation()->getLongitude(); foreach ($result->getAddressComponents() as $ac) { if (in_array('postal_code', $ac->getTypes())) { $out['cap'] = $ac->getShortName(); } } return $out; }
/** * @expectedException \Ivory\GoogleMap\Exception\GeocodingException * @expectedExceptionMessage The geocoder response status can only be : ERROR, INVALID_REQUEST, OK, * OVER_QUERY_LIMIT, REQUEST_DENIED, UNKNOWN_ERROR, ZERO_RESULTS. */ public function testStatusWithInvalidValue() { $this->geocoderResponse->setStatus('foo'); }