SDKs overview
What3Words offers Software Development Kits (SDKs) to facilitate the integration of its geocoding service into various applications. These SDKs are designed to streamline the process of converting 3-word addresses into geographical coordinates and vice-versa, as well as providing enhanced features like AutoSuggest for user input. By encapsulating API calls and handling request/response parsing, the SDKs aim to reduce development time and complexity for developers working with the What3Words Public API.
The available SDKs support a range of popular programming languages, allowing developers to choose the most suitable tool for their specific platform or application environment. Each SDK typically includes functions for:
- Convert to coordinates: Translating a 3-word address (e.g.,
///filled.count.soap) into latitude and longitude coordinates. - Convert to 3-word address: Converting latitude and longitude coordinates into a 3-word address.
- AutoSuggest: Providing real-time suggestions for 3-word addresses as a user types, improving accuracy and reducing input errors. This feature can incorporate factors such as current location, language, and the country for improved relevance.
- Grid Section: Retrieving a section of the What3Words grid, which can be useful for displaying local areas.
Official SDKs by language
What3Words maintains a suite of official SDKs for commonly used programming languages and platforms. These SDKs are developed and supported by What3Words to ensure compatibility with the latest API versions and to provide a consistent developer experience across different environments. The official offerings prioritize stability, security, and adherence to best practices for each respective language ecosystem.
| Language | Package/Library Name | Installation Method | Maturity |
|---|---|---|---|
| JavaScript | what3words (npm) |
npm install what3words |
Stable |
| Python | what3words (pip) |
pip install what3words |
Stable |
| Java | com.what3words:w3w-java-wrapper (Maven/Gradle) |
Add to pom.xml or build.gradle |
Stable |
| Swift | What3Words (Swift Package Manager/CocoaPods) |
Add via Xcode or Podfile |
Stable |
| Kotlin | io.github.what3words:kotlin-wrapper (Maven/Gradle) |
Add to pom.xml or build.gradle |
Stable |
| PHP | what3words/php-wrapper (Composer) |
composer require what3words/php-wrapper |
Stable |
| Ruby | what3words (RubyGems) |
gem install what3words |
Stable |
| C# | What3words.CSharp.Core (NuGet) |
Install-Package What3words.CSharp.Core |
Stable |
Installation
Installing a What3Words SDK typically follows the standard package management practices for the respective programming language. Each SDK is distributed through its ecosystem's primary package manager, simplifying dependency management and integration into existing projects. Before installation, developers generally need an API key, which can be obtained by registering on the What3Words developer website.
JavaScript (Node.js/Browser)
For JavaScript projects, the SDK is available via npm:
npm install what3words
It can then be imported into your project:
import { What3wordsV3 } from '@what3words/api'; // ES Module
// const { What3wordsV3 } = require('@what3words/api'); // CommonJS
Python
Python developers can install the SDK using pip:
pip install what3words
Once installed, import the library:
import what3words
Java (Maven/Gradle)
For Java applications, the SDK is available through Maven Central. Add the following dependency to your pom.xml (Maven) or build.gradle (Gradle):
Maven:
<dependency>
<groupId>com.what3words</groupId>
<artifactId>w3w-java-wrapper</artifactId&n>
<version>3.x.x</version> <!-- Replace with the latest version -->
</dependency>
Gradle:
implementation 'com.what3words:w3w-java-wrapper:3.x.x' // Replace with the latest version
Swift (iOS/macOS)
For Apple platforms, the SDK can be integrated using Swift Package Manager or CocoaPods.
Swift Package Manager: In Xcode, go to File > Add Packages and enter https://github.com/what3words/w3w-swift-wrapper as the package URL.
CocoaPods: Add the following to your Podfile:
pod 'What3Words', '~> 3.0'
Quickstart example
This example demonstrates how to use the Python SDK to convert a 3-word address to coordinates and vice-versa. This process generally involves initializing the SDK with an API key and then calling the respective conversion methods. The What3Words API Reference provides further details on available endpoints and parameters.
import what3words
# Initialize the What3Words API client with your API key
# Replace 'YOUR_API_KEY' with your actual What3Words API key
api = what3words.Geocoder(api_key='YOUR_API_KEY')
# --- Convert 3-word address to coordinates ---
three_word_address = '///filled.count.soap'
try:
# Call the convertToCoordinates method
result_to_coords = api.convert_to_coordinates(three_word_address)
if result_to_coords.is_successful():
coords = result_to_coords.get_data()
print(f"3-word address: {three_word_address}")
print(f" > Latitude: {coords['coordinates']['lat']}")
print(f" > Longitude: {coords['coordinates']['lng']}")
else:
print(f"Error converting '{three_word_address}' to coordinates: {result_to_coords.get_error()}")
except Exception as e:
print(f"An error occurred: {e}")
print("\n---")
# --- Convert coordinates to 3-word address ---
latitude = 51.520847
longitude = -0.195521
try:
# Call the convertTo3wa method
result_to_3wa = api.convert_to_3wa(latitude, longitude)
if result_to_3wa.is_successful():
three_word_address_result = result_to_3wa.get_data()
print(f"Coordinates: Lat {latitude}, Lng {longitude}")
print(f" > 3-word address: {three_word_address_result['words']}")
else:
print(f"Error converting coordinates to 3-word address: {result_to_3wa.get_error()}")
except Exception as e:
print(f"An error occurred: {e}")
This example demonstrates the core geocoding functionality. For advanced features like AutoSuggest, the SDKs provide dedicated methods that can be configured with parameters such as country filters and focus circles to refine suggestions.
Community libraries
While What3Words provides official SDKs, the developer community sometimes contributes unofficial libraries or integrations that extend functionality or adapt the service to niche platforms. These community-driven efforts may not receive direct support from What3Words and their maintenance status can vary.
Developers often create community libraries for several reasons, including:
- Specialized use cases: Tailoring the What3Words API for specific frameworks or application types not directly covered by official SDKs.
- Language support: Providing wrappers for less common programming languages.
- Feature extensions: Adding supplementary features or UI components built on top of the core API.
- Learning and experimentation: Educational projects or proofs-of-concept.
When considering community libraries, it is advisable to evaluate their documentation, active maintenance, and community support. Resources like GitHub and language-specific package repositories are common places to discover such libraries. For instance, the Python Package Index (PyPI) or npm registry may host unofficial wrappers, although developers should prioritize official libraries for production environments due to guaranteed support and updates.
For developers interested in contributing to or reviewing community projects, platforms like GitHub host numerous open-source initiatives. For example, GitHub hosts various projects related to location services, including those that might integrate or adapt the What3Words API, as seen in general AWS SDK for PHP developer guides that often inspire community wrapper patterns for other APIs.