In version 4.0, the Android API Wrapper library changed significantly. This guide will help you gradually adapt your existing code to the new wrapper.

Note:

1Step 1: Introduction to the Core Library#

The core library establishes essential models and interfaces that maintain consistency across various other libraries. Significant changes have been made by substituting existing models with those from the core library. It is imperative to update your code accordingly to utilise these new models.

Android v4 Tutorial: For a comprehensive guide to the latest version 4.x, see the Android tutorial.

Model Replacements

Android v3 modelsAndroid v4 models
com.what3words.javawrapper.response.SuggestionWithCoordinatescom.what3words.core.types.domain.W3WSuggestion
com.what3words.javawrapper.request.AutosuggestOptionscom.what3words.core.types.options.W3WAutosuggestOptions
com.what3words.javawrapper.response.Coordinatescom.what3words.core.types.geometry.W3WCoordinates
com.what3words.javawrapper.response.Squarecom.what3words.core.types.geometry.W3WRectangle
com.what3words.core.domain.language.W3WLanguagecom.what3words.core.types.language.W3WLanguage
com.what3words.javawrapper.request.BoundingBoxcom.what3words.core.types.geometry.W3WRectangle
com.what3words.androidwrapper.voice.Microphonecom.what3words.core.datasource.voice.audiostream.W3WMicrophone

2Step 2: Transition to W3WApiTextDataSource and W3WApiVoiceDataSource#

The Android API Wrapper version 3 What3WordsV3 has been restructured into two distinct classes:

  • W3WApiTextDataSource: Handles text-based tasks like address searching and conversions.
  • W3WApiVoiceDataSource: Specialises in voice-based address suggestions.

For more information on using version 4.x, see the latest Android tutorial.

3Step 3: Method Changes List#

convertToCoordinates

Converts a what3words address to coordinates.

Android v3
val wrapper = What3WordsV3(API_KEY, activityContext)
val result = wrapper.convertToCoordinates(words).execute()

Parameters:

  • words: String (the what3words address to convert)

Return: ConvertToCoordinates (coordinates corresponding to the what3words address)

Android v4
val textDataSource = W3WApiTextDataSource.create(context, API_KEY) 
val result = textDataSource.convertToCoordinates(words) // Must run on background thread

Parameters:

  • words: String (the what3words address to convert)

Return: W3WResult<W3WAddress> (result containing the coordinates)

For more details and instructions, see Convert to Coordinates Example.

convertTo3wa

Converts coordinates to a what3words address.

Android v3
val wrapper = What3WordsV3(API_KEY, activityContext)
val result = wrapper.convertTo3wa(coordinates).execute()

Parameters:

  • coordinates: Coordinates (latitude and longitude to convert)

Return: ConvertTo3WA (the corresponding what3words address)

Android v4
val textDataSource = W3WApiTextDataSource.create(context, API_KEY) 
val result = textDataSource.convertTo3wa(coordinates, language) // Must run on background thread

Parameters:

  • coordinates: W3WCoordinates (latitude and longitude to convert)
  • language: W3WLanguage (the language for the what3words address)

Return: W3WResult<W3WAddress> (result containing the what3words address)

For more details and instructions, see Convert to what3words Address Example.

AutoSuggest

Provides address suggestions based on a partial or full what3words address.

Android v3
val wrapper = What3WordsV3(API_KEY, activityContext)
val result = wrapper.autosuggest(word).execute()

Parameters:

  • word: String (the partial or full what3words address to get suggestions for)

Return: Autosuggest (list of suggested addresses)

Android v4
val textDataSource = W3WApiTextDataSource.create(context, API_KEY) 
val result = textDataSource.autosuggest(word, options) // Must run on background thread

Parameters:

  • word: String (the partial or full what3words address to get suggestions for)
  • options: W3WAutosuggestOptions? (optional parameters to refine suggestions)

Return: W3WResult<List<W3WSuggestion>> (result containing the list of suggestions)

For more details and instructions, see Autosuggest Example.

availableLanguages

Fetches the list of available languages for what3words addresses.

Android v3
val wrapper = What3WordsV3(API_KEY, activityContext)
val result = wrapper.availableLanguages().execute()

Return: AvailableLanguages (set of supported languages)

Android v4
val textDataSource = W3WApiTextDataSource.create(context, API_KEY) 
val result = textDataSource.availableLanguages() // Must run on background thread

Return: W3WResult<Set<W3WProprietaryLanguage>> (result containing the set of supported languages)

For more details and instructions, see Get Available Languages Example.

gridSection

Retrieves a section of the what3words address grid for a specified bounding box.

Android v3
val wrapper = What3WordsV3(API_KEY, activityContext)
val result = wrapper.gridSection(boudingBox).execute()

Parameters:

  • boundingBox: BoundingBox (the area to get the grid section for)

Return: GridSection (section of the grid)

Android v4
val textDataSource = W3WApiTextDataSource.create(context, API_KEY) 
val result = textDataSource.gridSection(boundingBox) // Must run on background thread
  • Parameters:
    • boundingBox: W3WRectangle (the area to get the grid section for)
  • Return: W3WResult<W3WGridSection> (result containing the section of the grid)

For more details and instructions, see Grid Section Example.

Voice AutoSuggest

Provides address suggestions based on voice input.

Android v3
val wrapper = What3WordsV3(API_KEY, activityContext)
val result = wrapper.autosuggest(microphone, voiceLanguage)
    .onSuggstions { suggestions ->
        // Handle the suggestions
    }
    .onError { error ->
        // Handle the error
    }

Parameters:

  • microphone: Microphone (the audio input device)
  • voiceLanguage: String (the language for voice recognition)

Return:

  • suggestions: List<Suggestion> (list of suggested addresses)
  • error: APIResponse.What3WordsError (error information)
Android v4
val voiceDataSource = W3WApiVoiceDataSource.create(API_KEY) 
val result = voiceDataSource.autosuggest(
        audioStream,
        voiceLanguage,
        options,
        onSpeechDetected,
    ) { result ->
        // Handle result
    }

Parameters:

  • input: W3WAudioStream (the audio input stream)
  • voiceLanguage: W3WLanguage (the language for voice recognition)
  • options: W3WAutosuggestOptions? (optional parameters to refine suggestions)
  • onSpeechDetected: ((String) -> Unit)? (callback for speech detection)

Return:

  • result: W3WResult<List<W3WSuggestion>> (result containing the list of suggestions)

For more details and instructions, see Voice Autosuggest Example.

4Step 4: AutosuggestHelper#

In the previous version, AutosuggestHelper relied on the Android API Wrapper v3 (What3WordsV3). Now, it has transitioned to using W3WApiTextDataSource.

Android v3
val what3words = What3WordsV3("YOUR_API_KEY_HERE", this)
val autosuggestHelper = AutosuggestHelper(what3words)
Android v4
val dataSource = W3WApiTextDataSource.create(context, "YOUR_API_KEY_HERE")
val autosuggestHelper = AutosuggestHelper(dataSource)

For more details and instructions, see AutoSuggestHelper.

esc
↑ ↓ to choose↵ to openesc to close