OpenCage.Geocode 1.6.0

dotnet add package OpenCage.Geocode --version 1.6.0
NuGet\Install-Package OpenCage.Geocode -Version 1.6.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="OpenCage.Geocode" Version="1.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenCage.Geocode --version 1.6.0
#r "nuget: OpenCage.Geocode, 1.6.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.
// Install OpenCage.Geocode as a Cake Addin
#addin nuget:?package=OpenCage.Geocode&version=1.6.0

// Install OpenCage.Geocode as a Cake Tool
#tool nuget:?package=OpenCage.Geocode&version=1.6.0

OpenCage Data Geocoding Library for .NET 6.0

A .NET 6.0 library that provides geocoding and reverse geocoding of locations using the OpenCage Geocoder geocoder.

Dependencies and Requirements

  • .NET 6.0
  • ServiceStack.Text.Core ver 6.4 (added via Nuget)
  • OpenCageGeocoder key - get yours FREE

Usage (Geocoding)

Reference the library using Nuget

Create an instance of the geocoder library, passing a valid OpenCage Data Geocoder API key as a parameter to the geocoder library's constructor:

var geoCoder = new GeoCoder("YOUR_KEY");

Pass a string containing the query or address to be geocoded to the library's Geocode method:

var result = await geoCoder.GeoCodeAsync("82 Clerkenwell Road, London");

You will get a strongly typed GeocoderResponse object returned.

There are many parameters for language, country, bounds and more see https://opencagedata.com/api for explanations of them all or read the documentation provided for each parameter in Visual Studio.

Putting all of this together as a console app, a complete sample with a basic and advanced usage would look like this:

var geoCoder = new GeoCoder("YOURKEYHERE");

// simplest example with no optional parameters
var result = await geoCoder.GeoCodeAsync("newcastle");

//  example with lots of optional parameters
var result2 = await geoCoder.GeoCodeAsync("newcastle", countrycode: "gb", limit: 2, minConfidence: 6, language: "en", abbrv: true, noAnnotations:true, noRecord: true, addRequest: true);

Usage (Reverse Geocoding)

Reverse geocoding is almost identical but you pass in a latitude and longitude pair:

var geoCoder = new Geocoder("YOUR_KEY");
var result = geoCoder.ReverseGeoCodeAsync(51.4277844, -0.3336517);
            
result.PrintDump(); // ServiceStack human readable object dump to console

There are many parameters for language, limiting results and more see https://opencagedata.com/api for explanations of them all or read the documentation provided for each parameter in Visual Studio.

Further Examples

Further examples of a .Net Core and .Net 4.6.1 console application are available within the solution as projects 'GeocoderDemo.Net461' and 'GeocoderDemo.NetCore'.

Error handling

Any errors that the geocoding service returns will be found in the RequestStatus property of the GeocoderResponse object. RequestStatus contains the standard HTTP error status code as the Code property and a more helpful error message in the Message property.

Best practices

Before starting to use the OpenCage geocoder in your projects we advice you read the Best Practices document to ensure you get the best results possible.

Rate limiting

Two error codes are used when any rate limiting has come into effect:

  1. 402 - 'Valid request but quota exceeded (payment required)'
  2. 429 - 'Too many requests (too quickly, rate limiting)'

For more about the rate limits read the OpenCage Geocoder API Documentation.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
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.6.0 5,620 10/27/2022

Adding in recent community updates and fixes, thanks to all who contributed