All tutorials
.NET
The .NET API wrapper is useful for .NET developers who wish to seamlessly integrate the what3words API into their applications, without the hassle of having to manage the low level API calls themselves.
A full example of a .NET application is available in our GitHub repository.
The what3words API is a fast, simple interface which allows you to convert 3 word addresses such as ///index.home.raft to latitude and longitude coordinates such as (-0.203586, 51.521251) and vice versa. It features a powerful AutoSuggest function, which can validate and correct user input and limit it to certain geographic areas (this powers the search box on our map site). It allows you to request a section of the what3words grid (which can be requested as GeoJSON for easy display on online maps), and to request the list of all languages supported by what3words. For advanced users, AutoSuggest can be used to post-process voice output.
All coordinates are latitude,longitude pairs in standard WGS-84 (as commonly used worldwide in GPS systems). All latitudes must be in the range of -90 to 90 (inclusive).
Installation
The artifact is available through NuGet Package what3words.dotnet.wrapper
Setup
Instantiate an instance of What3WordsV3, from which all API requests can be made
var wrapper = new What3WordsV3("YOUR_API_KEY_HERE");
If you run our Enterprise Suite API Server yourself, you may specify the URL to your own server like so:
var wrapper = new What3Words("YOUR_API_KEY_HERE", "https://api.yourserver.com")
Usage
Convert to 3 word address
This function converts coordinates (expressed as latitude and longitude) to a 3 word address.
More information about ConvertTo3wa
, including returned results, is available in the what3words REST API documentation.
Find the words for (51.222011, 0.152311
):
var result = await wrapper.ConvertTo3WA(new Coordinates(51.222011, 0.152311)).RequestAsync();
Convert to coordinates
This function converts a 3 word address to a position, expressed as coordinates of latitude and longitude.
This function takes the words parameter as a string of 3 words 'filled.count.soap'
More information about ConvertToCoordinates
, including returned results is available in the what3words REST API documentation.
Find the words for ///filled.count.soap:
var result = await wrapper.ConvertToCoordinates("filled.count.soap").RequestAsync();
AutoSuggest
When presented with a 3 word address that may be incorrectly entered, AutoSuggest returns a list of potential correct 3 word addresses. It needs the first two words plus at least the first character of the third word to produce suggestions.
This method provides corrections for mis-typed words (including plural vs singular), and words being in the wrong order.
Optionally, clipping can narrow down the possibilities, and limit results to:
- One or more countries
- A geographic area (a circle, box or polygon)
This dramatically improves results, so we recommend that you use clipping if possible.
To improve results even further, set the focus
to user’s current location. This will make autosuggest
return results which are closer to the user.
More information about autosuggest
, including returned results is available in the what3words REST API documentation.
Example: Basic AutoSuggest call
var result = await wrapper.Autosuggest("index.home.r").RequestAsync();
Example: AutoSuggest, Focus on (51.4243877,-0.34745
)
var result = await wrapper.Autosuggest("index.home.r", new AutosuggestOptions().SetFocus(51.4243877,-0.34745)).RequestAsync();
Grid section
Grid Section returns a section of the what3words 3m x 3m grid as a set of horizontal and vertical lines covering the requested area, which can then be drawn onto a map.
The requested box must not exceed 4km from corner to corner, or a BadBoundingBoxTooBig
error will be returned.
More information about GridSection
, including returned results is available in the what3words REST API documentation.
Get a grid for (51.222609, 0.152898
) in the south-west, and (51.222011, 0.152311
in the north-east:
var result = await wrapper.GridSection(new Coordinates(51.222011, 0.152311), new Coordinates(51.222609, 0.152898)).RequestAsync();
Available languages
This function returns the currently supported languages. It will return the two letter code, and the name of the language both in that language and in English.
More information about AvailableLanguages
, including returned results is available in the what3words REST API documentation.
var result = await wrapper.AvailableLanguages().RequestAsync();
Handling errors
Success or failure of an API call can be determined through the use of the IsSuccessful
propriety.
If it’s been determined that an API call was not successful, Error
type and Message
values which represent the error, are accessible from through the Error
propriety.
var autosuggestResult = await api.Autosuggest( "freshen.overlook.clo", new AutosuggestOptions().SetClipToCountry(new List<string> { "fr", "de" }) ).RequestAsync(); if (autosuggestResult.IsSuccessful) { ... } else { if (autosuggestResult.Error.Error == What3WordsError.BadClipToCountry) { // Invalid country clip is provided Console.WriteLine($"BadClipToCountry: {autosuggestResult.Error.Message}"); } }