Android Wrapper for the what3words Web API

An Android library to use the what3words REST API.

To make use of the what3words REST API in your Android applications, you can use the Java Wrapper. Aside from having to undertake networking operations outside of the main application thread, the use of the Java Wrapper is exactly the same in an Android runtime as it is in a traditional Java virtual machine (JVM).

Main Thread Loop

Because Android does not allow networking operations on the main application thread, API calls need to be made in a background thread. It is recomended to use IntentService functionality to perform asynchronous requests in a production application, however, for simple demonstration purposes API requests can be made in a simple child thread.

new Thread(new Runnable() {
    public void run() {
        // For all requests a what3words API key is needed
        What3WordsV3 api = new What3WordsV3("what3words-api-key");
        
        // Create and execute a request with the 3 word address such as "filled.count.soap"
        ConvertToCoordinates coordinates = api.convertToCoordinates("filled.count.soap").execute();
        
        if (coordinates.isSuccessful()) { // the request was successful
            System.out.println("Coordinates: " + coordinates);
        
        } else { // the request was not successful
            What3WordsError error = coordinates.getError();
        
            if (error == What3WordsError.BAD_WORDS) { // The three word address provided is invalid
                System.out.println("BadWords: " + error.getMessage());
        
            } else if (error == What3WordsError.INTERNAL_SERVER_ERROR) { // Server Error
                System.out.println("InternalServerError: " + error.getMessage());
        
            } else if (error == What3WordsError.NETWORK_ERROR) { // Network Error
                System.out.println("NetworkError: " + error.getMessage());
        
            } else { // Unknown Error
                System.out.println(error + ": " + error.getMessage());
        
            }
        }
    }
}).start();

Further Reading

See the Java Wrapper for complete documentation describing the usage of this wrapper.

See the what3words GitHub repository for access to full source code of the Java wrapper and further documentation.

Complete examples of each endpoint are also available: -