示例#1
0
 /**
  * 
  * @param array $resultDecoded
  * @return LookupResult
  */
 private function convertToLookupResult($resultDecoded)
 {
     $resultProp = $resultDecoded['resourceSets'][0]['resources'][0];
     $address = $resultProp['address'];
     $geocode = $resultProp['geocodePoints'][0]['coordinates'];
     $countryIso = array_search($address['countryRegion'], LookupResult::$ISO_TABLE);
     if ($countryIso) {
         $countryIso = LookupResult::remapIso($countryIso);
     }
     return new LookupResult($address['postalCode'], $countryIso, $geocode[1], $geocode[0], $resultProp['adminDistrict'], $address['countryRegion']);
 }
 /**
  *
  * @param string $postalCode
  * @param string $countryIso
  * @param string $city
  * @return \models\entities\GeocodeCached
  */
 public function postalCodeLookup($postalCode, $countryIso, $city = null)
 {
     $lookupWhere = new \DbTableWhere();
     $countryIso = LookupResult::remapIso($countryIso);
     $lookupWhere->where('country_iso', $countryIso);
     $postalCode = str_replace(' ', '', $postalCode);
     if ($postalCode) {
         $lookupWhere->where(new \DbTableFunction("REPLACE(postal_code, ' ', '')"), $postalCode);
     } elseif ($city) {
         $lookupWhere->where('city', $city);
     }
     //var_dump($lookupWhere);exit;
     $cached = $this->geocodeCachedManager->getEntityWhere($lookupWhere);
     if ($cached) {
         return $cached;
     }
     $country = LookupResult::$ISO_TABLE[$countryIso];
     $address = preg_replace('/\\s+/', ' ', "{$postalCode} {$city}, {$country}");
     return $this->addressLookup(trim($address), array('postal_code' => $postalCode, 'city' => $city, 'country_iso' => $countryIso));
 }