Geocoding¶
Geocoder
¶
Google geocoding client.
Purpose
Resolves addresses and coordinates and optionally caches geocoding results.
Attributes:
| Name | Type | Description |
|---|---|---|
maps |
Optional[Map]
|
Google Maps gateway used for requests. |
cache |
Optional[BaseCache]
|
Optional cache for resolved locations. |
_maps |
Map
|
Google Maps gateway used by geocoding methods. |
_cache |
Optional[BaseCache]
|
Optional cache used internally. |
prefix |
Optional[str]
|
Namespace prefix for generated cache keys. |
data |
Optional[Dict]
|
Most recently retrieved API payload. |
output |
Optional[Dict]
|
Most recently normalized location record. |
parts |
Optional[Tuple]
|
Current cache-key components. |
city |
Optional[str]
|
Current city input. |
address |
Optional[str]
|
Current address input. |
state |
Optional[str]
|
Current state input. |
country |
Optional[str]
|
Current country or region bias. |
comps |
Optional[Dict[str, str]]
|
Extracted address component values. |
key |
Optional[str]
|
Cache key for the current lookup. |
query |
Optional[str]
|
Current geocoding search value. |
latitude |
Optional[float]
|
Current latitude in decimal degrees. |
longitude |
Optional[float]
|
Current longitude in decimal degrees. |
Initialize geocoding with a Google Maps gateway and optional cache.
Purpose
Initialize geocoding with a Google Maps gateway and optional cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maps
|
Map
|
Initialized Google Maps API gateway. |
required |
cache
|
Optional[BaseCache]
|
Optional geocoding cache. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Initializes instance state. |
Source code in mapping.py
Methods:¶
key_for
¶
Purpose
Create a stable cache key from a namespace prefix and one or more string parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Cache namespace or operation prefix. |
required |
parts
|
List[str]
|
Values that uniquely identify the request. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Normalized cache key. |
Source code in mapping.py
validate_coordinates
¶
Purpose
Validate and normalize a latitude/longitude coordinate pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
Latitude in decimal degrees. |
required |
longitude
|
float
|
Longitude in decimal degrees. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Tuple[float, float]: Validated latitude and longitude. |
Source code in mapping.py
freeform
¶
Purpose
Geocode a free-form address string. Optionally bias by country code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
Any human-entered address string. |
required |
country
|
str
|
ISO-3166 alpha-2 country code to bias results, such as 'US' or 'FR'. Pass an empty string to disable country bias. |
'US'
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | None
|
Dict[str, Any] | None: Flattened geocode result. |
Raises:
| Type | Description |
|---|---|
NotFound
|
Raised when no results are returned. |
Source code in mapping.py
reverse
¶
Purpose
Reverse geocode a latitude/longitude pair into a canonical address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
Latitude in decimal degrees. |
required |
longitude
|
float
|
Longitude in decimal degrees. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | None
|
Dict[str, Any] | None: Flattened geocode result. |
Raises:
| Type | Description |
|---|---|
NotFound
|
Raised when no reverse-geocode result is returned. |
Source code in mapping.py
city_state_country
¶
Purpose
Geocode a structured city/state/country triple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
city
|
str
|
City or locality. |
required |
state
|
str
|
State, province, territory, or region. May be empty. |
required |
country
|
str
|
Country name or ISO-2 country code. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | None
|
Dict[str, Any] | None: Flattened geocode result. |
Raises:
| Type | Description |
|---|---|
NotFound
|
Raised when no result is available. |
Source code in mapping.py
batch_freeform
¶
Purpose
Geocode a list of free-form addresses while preserving row-level success and failure status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addresses
|
List[str]
|
Address strings to geocode. |
required |
country
|
str
|
ISO-3166 alpha-2 country code used as a default country bias. |
'US'
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: List of flattened geocode results. Failed rows include geocode_status='error' and geocode_error. |