示例#1
0
 /**
  * Geocode address and retries if first attempt or value in session
  * is not geocoded
  *
  * @param Model\Constraint|Model\Location $address
  * @param bool $forceGeocoding
  * @return Model\Constraint|Model\Location
  */
 public function geocodeAddress($address, $forceGeocoding = FALSE)
 {
     $geocodedAddress = $this->coordinatesCache->getCoordinateByAddress($address);
     if ($forceGeocoding || !$geocodedAddress->isGeocoded()) {
         $fieldsHit = array();
         $geocodedAddress = $this->processAddress($address, $fieldsHit);
         $this->coordinatesCache->addCoordinateForAddress($geocodedAddress, $fieldsHit);
     }
     // In case the address without geocoded location was stored in
     // session or the geocoding did not work a second try is done
     if (!$forceGeocoding && !$geocodedAddress->isGeocoded()) {
         $geocodedAddress = $this->geocodeAddress($geocodedAddress, TRUE);
     }
     return $geocodedAddress;
 }
 /**
  * Test for something
  *
  * @test
  * @throws \TYPO3\CMS\Core\Exception
  * @return void
  */
 public function locationWithAddressZipCityStateCountryGetStoredInSessionCache()
 {
     $this->coordinatesCache->flushCache();
     $data = array('address' => uniqid('Address'), 'zipcode' => substr(mktime(), -5), 'city' => uniqid('City'), 'state' => '', 'country' => uniqid('Country'));
     $constraint = $this->getConstraintStub($data);
     $coordinate = array('latitude' => $constraint->getLatitude(), 'longitude' => $constraint->getLongitude());
     $fields = array('address', 'zipcode', 'city', 'state', 'country');
     $this->coordinatesCache->addCoordinateForAddress($constraint, $fields);
     $fields = array('address', 'zipcode', 'city', 'state', 'country');
     $hash = $this->coordinatesCache->getHashForAddressWithFields($constraint, $fields);
     $this->assertEquals($coordinate, $this->coordinatesCache->getValueFromSession($hash));
 }