TaskHub provides a unified way to work with geographic data through the IGeoCodingService.
The implementation (e.g., Nominatim) is configured via appsettings.json.
"GeoCoding": {
"Nominatim": {
"BaseUrl": "https://nominatim.openstreetmap.org",
"UserAgent": "TaskHub-App"
}
}
Inject IGeoCodingService into your handlers or services.
public class UpdateJobLocationHandler(IGeoCodingService geoService, IJobRepository repository)
: ICommandHandler<UpdateJobLocationCommand, Result>
{
public async Task<Result> HandleAsync(UpdateJobLocationCommand cmd, CancellationToken ct)
{
// 1. Convert address to coordinates (Geocoding)
var coordsResult = await geoService.GeocodeAsync(cmd.Address, ct);
if (!coordsResult.IsSuccess) return coordsResult;
var coords = coordsResult.Data; // LatLng object
// 2. Convert coordinates to address (Reverse Geocoding)
var addressResult = await geoService.ReverseGeocodeAsync(coords.Latitude, coords.Longitude, ct);
// ... update repository
return ResultFactory.OnSuccess();
}
}
While Nominatim (OpenStreetMap) is provided out-of-the-box, you can implement your own provider (e.g., Google Maps, Azure Maps) by implementing the IGeoCodingService interface from TaskHub.Shared.GeoCoding.Abstractions.