OpenCage.Geocode.DotNetStandard 1.6.0

dotnet add package OpenCage.Geocode.DotNetStandard --version 1.6.0                
NuGet\Install-Package OpenCage.Geocode.DotNetStandard -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.DotNetStandard" 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.DotNetStandard --version 1.6.0                
#r "nuget: OpenCage.Geocode.DotNetStandard, 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.DotNetStandard as a Cake Addin
#addin nuget:?package=OpenCage.Geocode.DotNetStandard&version=1.6.0

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

OpenCage Data Geocoding Library for .Net Standard

A .NET Standard library (works in .Net core, .Net 4.6.1 and Xamarin projects) that provides geocoding and reverse geocoding of locations using the OpenCage Geocoder geocoder.

Dependencies and Requirements

  • .NET Standard 2.0
  • ServiceStack.Text.Core ver 1.0.44 (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 gc = new Geocoder("YOUR_KEY");

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

var result = gc.Geocode("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 gc = new Geocoder("YOURKEYHERE");

// simplest example with no optional parameters
var result = gc.Geocode("newcastle");

//  example with lots of optional parameters
var result2 = gc.Geocode("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 gc = new Geocoder("YOUR_KEY");
var reserveresult = gc.ReverseGeocode(51.4277844, -0.3336517);
            
reserveresult.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.

Older versions for pre .Net 4.6.1

The previous release of this library was not targeted at .Net Standard but at .Net 4.6. The nuget package for this is still available at https://www.nuget.org/packages/OpenCageGeocoder/ but will not be maintained so we recommend using this new library and updating to a supported .Net version.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 4,981 10/20/2023
1.5.0 51,286 8/28/2019
1.4.0 2,994 6/19/2018
1.3.0 1,101 6/6/2018
1.2.0 1,129 12/9/2017

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