BCApis.Geocoding (bc_apis v0.1.0)

Geocoding service to convert city names to coordinates using Open-Meteo Geocoding API.

Open-Meteo provides free geocoding without requiring an API key.

Summary

Functions

Converts coordinates back to a location string for storage.

Converts a city name and country code to coordinates.

Get a list of major cities for a given country code. This is a simple static list - in a real application, you might want to use a more comprehensive database.

Functions

coordinates_to_location_string(lat, lon)

@spec coordinates_to_location_string(float(), float()) :: String.t()

Converts coordinates back to a location string for storage.

Parameters

  • lat: Latitude (float)
  • lon: Longitude (float)

Returns

  • Location string in "lat,lon" format

geocode_city(city, country_code, api_key)

@spec geocode_city(String.t(), String.t(), String.t()) ::
  {:ok, {float(), float()}} | {:error, term()}

Converts a city name and country code to coordinates.

Parameters

  • city: City name (string)
  • country_code: ISO 3166 country code (string)
  • api_key: Not used (Open-Meteo is free and doesn't require API key)

Returns

  • {:ok, {lat, lon}} on success
  • {:error, reason} on failure

get_major_cities(country_code)

@spec get_major_cities(String.t()) :: [String.t()]

Get a list of major cities for a given country code. This is a simple static list - in a real application, you might want to use a more comprehensive database.