sunny/api/geocoding
The module for interacting with the Geocoding API. Useful for getting the coordinates of a city to then get the weather forecast.
Types
The different parameters needed to make a request to the geocoding API
pub type GeocodingParams {
GeocodingParams(name: String, count: Int, language: Language)
}
Constructors
-
GeocodingParams(name: String, count: Int, language: Language)
Enumeration of the available languages for the geocoding API. Changing the language will impact the search results.
pub type Language {
English
German
French
Spanish
Italian
Portuguese
Russian
Turkish
Hindi
}
Constructors
-
English
-
German
-
French
-
Spanish
-
Italian
-
Portuguese
-
Russian
-
Turkish
-
Hindi
Represents a location on good old earth. Can be obtained with the geocoding API.
pub type Location {
Location(
latitude: Float,
longitude: Float,
id: Int,
name: String,
elevation: Float,
feature_code: String,
country_code: String,
country_id: Int,
population: option.Option(Int),
post_codes: option.Option(List(String)),
admin1: option.Option(String),
admin2: option.Option(String),
admin3: option.Option(String),
admin4: option.Option(String),
admin1_id: option.Option(Int),
admin2_id: option.Option(Int),
admin3_id: option.Option(Int),
admin4_id: option.Option(Int),
)
}
Constructors
-
Location( latitude: Float, longitude: Float, id: Int, name: String, elevation: Float, feature_code: String, country_code: String, country_id: Int, population: option.Option(Int), post_codes: option.Option(List(String)), admin1: option.Option(String), admin2: option.Option(String), admin3: option.Option(String), admin4: option.Option(String), admin1_id: option.Option(Int), admin2_id: option.Option(Int), admin3_id: option.Option(Int), admin4_id: option.Option(Int), )
Functions
pub fn get_first_result(
response_body: String,
) -> Result(Location, SunnyError)
Get the first Location
from the body of a HTTP request response. If your
location is not first, you can use get_result
instead.
You can get a request.Request
to the Forecast API by using get_request
.
pub fn get_request(
client: Client,
params: GeocodingParams,
) -> Request(String)
Get a request.Request(String)
according to the specified GeocodingParams
.
Once you made a request using your favorite HTTP client, pass the String
body to get_result
.
pub fn get_result(
response_body: String,
) -> Result(List(Location), SunnyError)
Get a List
of Location
from the body of a HTTP request response. If you
only want the first search result, you can use get_first_result
.
You can get a request.Request
to the Forecast API by using get_request
.
pub fn location_to_position(location: Location) -> Position
Converts a location to a position.
pub fn params(name: String) -> GeocodingParams
Creates a new GeocodingParams with the default parameters. Takes the name of the researched location (by name or by postal code).
Defaults :
- count : 10
- language : English These are the same defaults as the Open-Meteo API’s ones.
pub fn set_count(
params: GeocodingParams,
count: Int,
) -> GeocodingParams
Creates a new GeocodingParams from the one specified, changing its count field.
The count will be clamped between 1 and 100.
pub fn set_language(
params: GeocodingParams,
language: Language,
) -> GeocodingParams
Creates a new GeocodingParams from the one specified, changing its language field.