C++ SDK

The C++ SDK is a highly portable C++ library which works fully offline. The C++ SDK has all the functionality of our public API (HTTP), with the benefit of being offline and extremely high performance. The compiled library is around 2.5MB in size, and our language data is around 30MB in size for all 26 languages (specifying a subset of languages is an option). The code is highly optimised for speed and memory (RAM) footprint, making it suitable for embedded applications.

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

              
// what3words_sample.cpp
// Compile using
//     g++ -std=c++11 what3words_sample.cpp -lwhat3words -owhat3words_sample -I../include -L../lib

#include <iostream>
#include <what3words/what3words.h>

using namespace std;
using namespace what3words;

int main() {
    try {
        auto e = new_server_engine("/var/what3words/w3w-data/");

        auto p_coords = e->convert_to_coordinates("index.home.raft");
        if (p_coords)
            cout << "The 3 word address index.home.raft is at "
                 << p_coords->lat << ", " << p_coords->lng << ".\n\n";
        else
            cout << "index.home.raft is not a 3 word address.\n\n";

        Coordinates coords{51.521251, -0.203586};
        auto p_3wa = e->convert_to_3wa(coords, "en");
        if (p_3wa)
            cout << "The English 3 word address at 51.521251, -0.203586 is "
                 << *p_3wa << ".\n\n";
        else
            cout << "The 3WA at 51.521251, -0.203586 is not available.\n\n";

        auto search_results = e->search("index.home.rft", "en");
        cout << "Searching for 'index.home.rft':\n";
        for (auto s : search_results) {
            cout << "\t" << s.three_word_address
                 << " (" << s.language_code
                 << ")\tnear " << s.nearest_place.get_value_or("[no place]")
                 << ", " << s.country_code << "\n";
        }
    }
    catch (std::runtime_error &e) {
        cout << e.what();
        return 1;
    }

    return 0;
}