public function testResults()
 {
     $geocoderResult = $this->getMockBuilder('Ivory\\GoogleMap\\Services\\Geocoding\\Result\\GeocoderResult')->disableOriginalConstructor()->getMock();
     $results = array($geocoderResult);
     $this->geocoderResponse->setResults($results);
     $this->assertSame($results, $this->geocoderResponse->getResults());
 }
示例#2
0
 /**
  *
  * @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;
 }