What3WordsV3API 3.0.0.2

.NET Standard 2.0
NuGet\Install-Package What3WordsV3API -Version 3.0.0.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.
dotnet add package What3WordsV3API --version 3.0.0.2
<PackageReference Include="What3WordsV3API" Version="3.0.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add What3WordsV3API --version 3.0.0.2
#r "nuget: What3WordsV3API, 3.0.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install What3WordsV3API as a Cake Addin
#addin nuget:?package=What3WordsV3API&version=3.0.0.2

// Install What3WordsV3API as a Cake Tool
#tool nuget:?package=What3WordsV3API&version=3.0.0.2

What3WordsV3API

Unofficial .NET wrapper for Version 3 of the what3words API

All API methods are provided in a single class called W3WClient. You will need a what3words API key to be able to use the library, which you can obtain from the what3words after signing up for an account.

The following methods are available in the library:

  • ConvertTo3WA - Converts a provided latitude and longitude to a 3 word address.
  • ConvertToCoordinates - Converts a provided 3 word address to its corresponding latitude and longitude
  • AvailableLanguages - Returns a list of all available what3words languages
  • GridSection - Returns a section of a 3m x 3m what3words grid for the provided bounding box.
  • AutoSuggest - Takes a slightly incorrect 3 word address and suggests a list of valid 3 word addresses

There are also Asynchronous versions of all these methods, which are:

  • ConvertToW3AAsync
  • ConvertToCoordinatesAsync
  • AvailableLanguagesAsync
  • GridSectionAsync
  • AutoSuggestAsync

API Namespaces

You should include the following usings in your code to use the API wrapper:

using Curnow.Biz.What3WordsV3Net;
using Curnow.Biz.What3WordsV3Net.Enums;
using Curnow.Biz.What3WordsV3Net.Models;

Creating an instance of W3WClient

Creating an instance of the API wrapper is very easy, you simply need to supply your API key as follows:

W3WClient w3w = new W3WClient("<<your api key>>");

ConvertTo3WA Example

AddressResponse response = w3w.ConvertTo3WA(51.520847, -0.19552);
Console.WriteLine($"Country: {response.country}\nWords: {response.words}\n{response.language}");

There is an optional language parameter that can be used on this method. If language isn't supplied, the default used is en (English):

AddressResponse response = w3w.ConvertTo3WA(51.520847, -0.19552, "fr");
Console.WriteLine($"Country: {response.country}\nWords: {response.words}\n{response.language}");

ConvertToCoordinates

AddressResponse response = w3w.ConvertToCoordinates("pinch","veal","sector");
Console.WriteLine($"Country: {response.country}\nURL@ {response.map}\nCoords: {response.coordinates.lat},{response.coordinates.lng}");

AddressResponse response = w3w.ConvertToCoordinates("pinch","veal","sector","fr");
Console.WriteLine($"Country: {response.country}\nURL@ {response.map}\nCoords: {response.coordinates.lat},{response.coordinates.lng}");

AvailableLanguages

LanguagesResponse response = w3w.AvailableLanguages();
response.languages.ForEach(l => { Console.WriteLine($"Native: {l.nativeName} - Code: {l.code} - Name: {l.name}"); });

GridSection

GridSectionResponse response = w3w.GridSection(new BoundingBox
{
    South = 52.207988,
    West = 0.116126,
    North = 52.208867,
    East = 0.117540
});
response.lines.ForEach(l => { Console.WriteLine($"Start: {l.start.lng}, {l.start.lat} End: {l.end.lng}, {l.end.lat}"); });

AutoSuggest

There are many optional parameters that can be supplied with this method call. Please refer to the what3words API documentation for this.

AutoSuggestResponse response = w3w.AutoSuggest("plan.clips.a");
foreach (var r in response.suggestions)
    Console.WriteLine($"Country: {r.country}\nNearest: {r.nearestPlace}\nWords: {r.words}\ndistancetoFocus: {r.distanceToFocusKm}\nRank: {r.rank}\nLanguage: {r.language}\n\n");

Handling Errors

The library handles an exceptions by throwing an exception of the type W3WException. There are specific errors returned by the what3words API based on HTTP Response code. Please refer to the what3words API documentation for this information.

try
{
  ...
}
catch(W3WException e)
{
    Console.WriteLine($"Error Code: {e.W3WCode} - Message: {e.W3WMessage}");
}
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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
3.0.0.2 2,350 7/16/2020

New release of package which is now targeted for .NET Standard 2.0