Java SDK

The Java SDK works offline. It is a simple wrapper which wraps our C++ core, providing you with all of the power and functionality that's available in the API. However, it has the benefit of being offline and extremely fast.

Some of the features:

  • Conversion of 3 word address to coordinate
  • Conversion of coordinates to 3 word addresses
  • Search for similar 3 word addresses (powered by Autosuggest)
  • Voice search

For access to this SDK, or for more information, please contact us at support@what3words.com

Sample code

              
IServerEngine w3wEngine = Engines.newServerEngine("/var/what3words/w3w-data");

// 1) Convert to Coordinates
Optional<Coordinates> maybeCoordinates = w3wEngine.convertToCoordinates("index.home.raft");
if (!maybeCoordinates.isPresent()) {
    // ERROR: The 3WA at this coordinate is not available
    System.out.printf("\t%s is not a valid 3WA.\n", addr);
} else {
    // SUCCESS: Got Coordinates - this is a valid 3WA
    // Middle of the square
    Coordinates coordinates = maybeCoordinates.get();
    System.out.printf("\tCoordinates: %s,%s\n", coordinates.lat, coordinates.lng);
}

// 2) Convert to 3WA
Coordinates inputCoordinates = new Coordinates(51.455905, -0.341492);
String lang = "en";
Optional<String> maybeThreeWordAddress = w3wEngine.convertTo3WA(inputCoordinates, lang);
if (!maybeThreeWordAddress.isPresent()) {
    // There is no 3WA at this coordinate
    System.out.printf("\tNo 3WA at %s,%s\n", inputCoordinates.lat, inputCoordinates.lng);
} else {
    // We have a 3WA now.
    String threeWordAddress = maybeThreeWordAddress.get();
    System.out.printf("\t3 word address: %s\n", threeWordAddress);
}

// 3) Search for similar 3WAs
List<Suggestion> suggestions = w3wEngine.search("index.home.rft", "en", Optional.<Coordinates>empty(), SearchInputType.TEXT);
System.out.printf("\tFound %d suggestions", suggestions.size());

for(Suggestion suggest : suggestions) {
    System.out.printf("\t3 word address: %s\n", suggest.threeWordAddress);
    System.out.printf("\t\tDistance to focus: %s\n", suggest.distanceToFocus.isPresent() ? suggest.distanceToFocus : "N/A");

    // If there are no major towns nearby, "nearestPlace" can be empty.
    System.out.printf("\t\tNearest place: %s\n", suggest.nearestPlace.orElse("No nearest place"));
    System.out.printf("\t\tCountry: %s\n", suggest.countryCode);
    System.out.printf("\t\tLanguage Code: %s\n\n", suggest.languageCode);
}