What3WordsV3API 3.0.0.2

dotnet add package What3WordsV3API --version 3.0.0.2                
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.
<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 and Polyglot Notebooks. 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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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
3.0.0.2 6,085 7/16/2020

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