ReverseGeocodeLib 1.2.2
dotnet add package ReverseGeocodeLib --version 1.2.2
NuGet\Install-Package ReverseGeocodeLib -Version 1.2.2
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="ReverseGeocodeLib" Version="1.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ReverseGeocodeLib" Version="1.2.2" />
<PackageReference Include="ReverseGeocodeLib" />
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 ReverseGeocodeLib --version 1.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ReverseGeocodeLib, 1.2.2"
#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 ReverseGeocodeLib@1.2.2
#: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=ReverseGeocodeLib&version=1.2.2
#tool nuget:?package=ReverseGeocodeLib&version=1.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ReverseGeocodeLib
Usage
Below is a basic example showing how to load the embedded country and city data and use the library to find the country and city for a given latitude/longitude. You must call the Load...Async methods before calling any Find... methods.
using System;
using System.Threading.Tasks;
using ReverseGeocodeLib;
class Program
{
static async Task Main(string[] args)
{
// Load embedded binary data (these should be embedded as resources)
await ReverseGeocodeService.LoadCountriesAsync();
await ReverseGeocodeService.LoadCitiesAsync();
// Specify coordinates (latitude, longitude). Example: London
double latitude = 51.5074;
double longitude = -0.1278;
// Find country and city
var countries = ReverseGeocodeService.FindCountry(latitude, longitude);
var cities = ReverseGeocodeService.FindCity(latitude, longitude);
// The methods return a list of tuples (Id, Name)
if (countries.Count > 0)
Console.WriteLine($"Country: {countries[0].Name} (Id: {countries[0].Id})");
else
Console.WriteLine("No country match.");
if (cities.Count > 0)
Console.WriteLine($"City: {cities[0].Name} (Id: {cities[0].Id})");
else
Console.WriteLine("No city match.");
// With an enclave the country could have more than 1 result, no way to tell which is correct
if (country == null || country.Count == 0)
{
Console.WriteLine("Country: Not found");
}
else
{
if (country.Count > 1)
Console.WriteLine($"Countries: {country[0].Item2} or {country[1].Item2}");
else
Console.WriteLine($"Country: {country[0].Item2}");
}
}
}
Other available lookups:
ReverseGeocodeService.LoadUSAStatesAsync()andFindUSAState(latitude, longitude)ReverseGeocodeService.LoadFranceDepartmentsAsync()andFindFranceDepartment(latitude, longitude)ReverseGeocodeService.LoadFranceRegionsAsync()andFindFranceRegion(latitude, longitude)ReverseGeocodeService.LoadUKCountiesAsync()andFindUKCounty(latitude, longitude)ReverseGeocodeService.LoadNetherlandsProvincesAsync()andFindNetherlandsProvince(latitude, longitude)
Notes:
- If no area matches the provided location, you’ll get an empty list.
- The library uses a point-in-polygon algorithm to test if the point is inside an area’s polygon(s).
- Embedded data files are expected as assembly resources with names such as
{AssemblyName}.Data.countries.bin,{AssemblyName}.Data.cities.bin, etc.- Confirm your
.csprojincludes:<ItemGroup> <EmbeddedResource Include="Data\countries.bin" /> <EmbeddedResource Include="Data\cities.bin" /> </ItemGroup>
- Confirm your
Acknowledgements to
https://github.com/InquisitorJax/Wibci.CountryReverseGeocode for the orignal project
https://simplemaps.com for map data
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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.
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.