CoolCMS API

GeocodingManager
in package

FinalYes

The only place that computes advert coordinates on save.

Both AdvertManager classes (Bazaar, Comcat) call it through AdvertRegionAddressTrait::applyCoordinates(); the front end "within X km" filter uses the internal Api action :Api:System:Region:geocode (resolveSearchText()). It composes RegionManager (municipality dataset), GeocodingCacheManager (cms_system_geocoding_cache) and the external geocoder.

Rules (precise is the module setting geocoding.precise_address):

  • imprecise address, or precise without a street: municipality center (the selected one, else an exact municipality/postcode match in the dataset); never Google; municipality not found gives GeocodingMiss;
  • precise address with a street: cache, then Google on a miss, then cache write; not found or error falls back to the municipality center, else GeocodingMiss.

NOTE: RegionManager::findLocality() / suggest() use raw SQL and never call clearDoctrine(), so running inside beforeSave does not detach the advert graph being saved.

Table of Contents

Constants

DATASET_LIMIT  : int = 10
DATASET_MIN_LEVEL  : int = 2
Dataset match on save: municipalities only (tree leaves).

Properties

$externalGeocoder  : ExternalGeocoder
$geocodingCacheManager  : GeocodingCacheManager
$regionManager  : RegionManager

Methods

__construct()  : mixed
lookupExternal()  : GeocodingLookup
Returns a usable `cms_system_geocoding_cache` answer (and increments `hits`), else asks the external geocoder and stores the result (a point or "not found").
resolveForAddress()  : GeocodingResult|GeocodingMiss
resolveSearchText()  : GeocodingLookup
Resolves free text of the "within X km" filter that the dataset does not know: cache, then Google, then cache write. The cache key country is the website localization country.
findDatasetMunicipality()  : RegionLocality|null
Finds the municipality from the address text when the advert has none selected (an old advert placed on a country/county): 1. full postcode: municipality with that postcode, preferring a matching name; 2. municipality name: only an unambiguous exact match ("Lhota" exists in dozens of districts, so it is not guessed).
findSelectedMunicipality()  : RegionLocality|null
Returns the selected region only when it is a municipality (tree leaf); a county/country center is not an advert location.
pickByName()  : RegionSuggestItem|null
pickByPostcode()  : RegionSuggestItem|null
suggestMunicipalities()  : array<int, RegionSuggestItem>

Constants

DATASET_MIN_LEVEL

Dataset match on save: municipalities only (tree leaves).

private int DATASET_MIN_LEVEL = 2

Properties

Methods

lookupExternal()

Returns a usable `cms_system_geocoding_cache` answer (and increments `hits`), else asks the external geocoder and stores the result (a point or "not found").

public lookupExternal(string $address, string $countryCode) : GeocodingLookup

A geocoder error (exhausted quota, network) is not stored for the address but trips a short circuit breaker: Google is not called at all for ERROR_RETRY_MINUTES minutes (the quota is shared by all queries) and error is returned, so the caller falls back to the municipality center or "not found". A cache hit for an address bypasses the breaker.

Parameters
$address : string
$countryCode : string
Return values
GeocodingLookup

resolveSearchText()

Resolves free text of the "within X km" filter that the dataset does not know: cache, then Google, then cache write. The cache key country is the website localization country.

public resolveSearchText(string $text, int|null $preferRegionId, int $languageId) : GeocodingLookup
Parameters
$text : string
$preferRegionId : int|null
$languageId : int
Return values
GeocodingLookup

findDatasetMunicipality()

Finds the municipality from the address text when the advert has none selected (an old advert placed on a country/county): 1. full postcode: municipality with that postcode, preferring a matching name; 2. municipality name: only an unambiguous exact match ("Lhota" exists in dozens of districts, so it is not guessed).

private findDatasetMunicipality(GeocodingRequest $request) : RegionLocality|null
Parameters
$request : GeocodingRequest
Return values
RegionLocality|null
On this page

Search results