Table of Contents

Class GeoLocator

Namespace
SimpleWeather
Assembly
SimpleWeather.dll

Provides helper methods for interacting with the OpenWeather geocoding APIs.

public class GeoLocator
Inheritance
GeoLocator
Inherited Members

Constructors

GeoLocator(string?)

Provides helper methods for interacting with the OpenWeather geocoding APIs.

public GeoLocator(string? apiKey = null)

Parameters

apiKey string

Optional API key used when issuing HTTP requests.

Methods

GetCitiesByNameAsync(string, string?, string?, CancellationToken)

Retrieves up to five matching cities based on name, state, and country filters.

public Task<List<string>> GetCitiesByNameAsync(string cityName, string? stateCode = null, string? countryCode = null, CancellationToken cancellationToken = default)

Parameters

cityName string

The city name to look up.

stateCode string

Optional ISO state code used for disambiguation.

countryCode string

Optional ISO country code used for disambiguation.

cancellationToken CancellationToken

Token used to cancel the HTTP request.

Returns

Task<List<string>>

A list of raw city payloads returned by the API.

GetCityNameByCoordinatesAsync(LatLong, CancellationToken)

Looks up the city name for the supplied coordinate pair.

public Task<string?> GetCityNameByCoordinatesAsync(LatLong latLong, CancellationToken cancellationToken = default)

Parameters

latLong LatLong

The latitude and longitude to reverse geocode.

cancellationToken CancellationToken

Token used to cancel the HTTP request.

Returns

Task<string>

The city name when available; otherwise null.

GetCityNameByCoordinatesAsync(double, double, CancellationToken)

Looks up the city name for the supplied latitude/longitude pair.

public Task<string?> GetCityNameByCoordinatesAsync(double lat, double lon, CancellationToken cancellationToken = default)

Parameters

lat double

The latitude to reverse geocode.

lon double

The longitude to reverse geocode.

cancellationToken CancellationToken

Token used to cancel the HTTP request.

Returns

Task<string>

The city name when available; otherwise null.

GetCoordinatesByCityNameAsync(string, string?, string?, CancellationToken)

Retrieves the first set of coordinates that matches the supplied city filters.

public Task<LatLong?> GetCoordinatesByCityNameAsync(string cityName, string? stateCode = null, string? countryCode = null, CancellationToken cancellationToken = default)

Parameters

cityName string

The city name to look up.

stateCode string

Optional ISO state code used for disambiguation.

countryCode string

Optional ISO country code used for disambiguation.

cancellationToken CancellationToken

Token used to cancel the HTTP request.

Returns

Task<LatLong?>

A LatLong when a city is found; otherwise null.

GetCoordinatesByPostCodeAsync(string, string, CancellationToken)

Retrieves coordinates by postal or ZIP code.

public Task<LatLong?> GetCoordinatesByPostCodeAsync(string postCode, string countryCode, CancellationToken cancellationToken = default)

Parameters

postCode string

The postal or ZIP code.

countryCode string

The ISO country code the postal code belongs to.

cancellationToken CancellationToken

Token used to cancel the HTTP request.

Returns

Task<LatLong?>

A LatLong when a match is found; otherwise null.