Geofox. Utils. Validation
(geofox_ex v0.1.1)
View Source
Validation utilities for postal codes and location names from the Geofox API.
This module provides functions for validating whether postal codes are within the HVV service area and for searching and validating location names.
Summary
Functions
Search for and validate location names.
Check if a postal code is within the HVV service area.
Functions
@spec check_name(Geofox.Client.t(), Geofox.Types.sd_name(), keyword()) :: {:ok, map()} | {:error, term()}
Search for and validate location names.
This function searches for locations matching the given name and returns detailed information including coordinates, distances, and travel times. It's similar to the check_name function in Core.Stations but provides additional validation features.
Parameters
client- The Geofox clientname_info- Location information ast:Types.sd_name/0opts- Optional parameters
Options
:language- Language code (default: "de"):version- API version (default: 1):filter_type- Filter type (default: "NO_FILTER"):max_list- Maximum number of results to return:max_distance- Maximum distance for location searches in meters:coordinate_type- Coordinate system (default: "EPSG_4326"):tariff_details- Include tariff zone information (default: false):allow_type_switch- Allow switching between location types (default: true)
Examples
# Search and validate a station name
name_info = %{name: "Hauptbahnhof", type: "STATION"}
{:ok, results} = Geofox.Utils.Validation.check_name(client, name_info)
# Search with distance and travel time information
{:ok, results} = Geofox.Utils.Validation.check_name(client, name_info,
max_distance: 1000,
tariff_details: true
)Returns
The response includes:
results- List of matching locations with:- Basic location information (name, id, type, coordinates)
distance- Distance in meters (if applicable)time- Travel time in minutes (if applicable)- Additional validation-specific metadata
@spec check_postal_code(Geofox.Client.t(), integer(), keyword()) :: {:ok, map()} | {:error, term()}
Check if a postal code is within the HVV service area.
This function validates whether a given postal code falls within the Hamburg public transport (HVV) service area, helping determine service availability for addresses.
Parameters
client- The Geofox clientpostal_code- The postal code to check (as integer)opts- Optional parameters
Options
:language- Language code (default: "de"):version- API version (default: 1):filter_type- Filter type (default: "NO_FILTER")
Examples
# Check if a Hamburg postal code is in HVV area
{:ok, result} = Geofox.Utils.Validation.check_postal_code(client, 20095)
is_hvv = result["isHVV"] # true or false
# Check a postal code outside Hamburg
{:ok, result} = Geofox.Utils.Validation.check_postal_code(client, 10115)
# Likely returns isHVV: falseReturns
The response includes:
isHVV- Boolean indicating whether the postal code is within HVV service area