Softalleys.Utilities.GeoToolkit 1.0.0

dotnet add package Softalleys.Utilities.GeoToolkit --version 1.0.0
                    
NuGet\Install-Package Softalleys.Utilities.GeoToolkit -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Softalleys.Utilities.GeoToolkit" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Softalleys.Utilities.GeoToolkit" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Softalleys.Utilities.GeoToolkit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Softalleys.Utilities.GeoToolkit --version 1.0.0
                    
#r "nuget: Softalleys.Utilities.GeoToolkit, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Softalleys.Utilities.GeoToolkit@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Softalleys.Utilities.GeoToolkit&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Softalleys.Utilities.GeoToolkit&version=1.0.0
                    
Install as a Cake Tool

Softalleys.Utilities.GeoToolkit

A .NET library for geocoding services, providing a flexible and extensible way to work with geocoding providers. The initial implementation includes support for Nominatim.

Features

  • Forward Geocoding: Search for coordinates from an address query.
  • Reverse Geocoding: Find addresses from geographic coordinates.
  • Place Lookup: Retrieve details of a place by its ID.
  • Structured Address Search: Perform searches using structured address components (for supported providers like Nominatim).
  • Extensible: Designed with interfaces to allow for other geocoding providers to be implemented.

Installation

This library can be installed via NuGet Package Manager.

dotnet add package Softalleys.Utilities.GeoToolkit

Getting Started

To get started, register the NominatimGeocodingService in your application's service container.

Using IConfiguration

You can configure the service using the appsettings.json file.

appsettings.json:

{
  "GeoToolkit": {
    "NominatimServerUrl": "https://nominatim.openstreetmap.org",
    "ShowLogs": true
  }
}

Program.cs:

builder.Services.AddNominatimGeoToolkit(builder.Configuration.GetSection("GeoToolkit"));

Using Action<GeoToolkitNominatimOptions>

Alternatively, you can configure the service directly in code.

Program.cs:

builder.Services.AddNominatimGeoToolkit(options =>
{
    options.NominatimServerUrl = "https://nominatim.openstreetmap.org";
    options.ShowLogs = true;
});

Usage

Inject the IGeocodingService or INominatimGeocodingService into your services or controllers.

public class GeocodingController(IGeocodingService geocodingService, INominatimGeocodingService nominatimService)
{
    // ... use the services
}

Forward Geocoding

To find locations for an address query:

var results = await geocodingService.SearchAsync("Eiffel Tower, Paris, France");
foreach (var result in results)
{
    Console.WriteLine($"{result.DisplayName}: ({result.Latitude}, {result.Longitude})");
}

Reverse Geocoding

To find an address for a given coordinate:

var results = await geocodingService.ReverseGeocodeAsync(48.858370, 2.294481);
foreach (var result in results)
{
    Console.WriteLine(result.DisplayName);
}

Lookup by ID

To look up a place by its OSM (OpenStreetMap) ID:

// Format: {OSM_TYPE}{OSM_ID} where type is (N)ode, (W)ay, or (R)elation
var place = await geocodingService.LookupByIdAsync("R148106");
if (place != null)
{
    Console.WriteLine(place.DisplayName);
}

Structured Search (Nominatim)

For more precise searches with Nominatim, you can use a structured address:

var structuredAddress = new StructuredAddress
{
    Street = "1600 Amphitheatre Parkway",
    City = "Mountain View",
    State = "CA",
    Country = "USA",
    PostalCode = "94043"
};

var results = await nominatimService.StructuredSearchAsync(structuredAddress);
foreach (var result in results)
{
    Console.WriteLine(result.DisplayName);
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 140 6/24/2025

Initial release of the GeoToolkit library.