what3words 0.0.0-dev+1 copy "what3words: ^0.0.0-dev+1" to clipboard
what3words: ^0.0.0-dev+1 copied to clipboard

outdated

A Dart library to use the what3words v3 API.

what3words w3w-dart-wrapper #

A Dart library to use the what3words v3 API.

API methods are grouped into a single service object which can be centrally managed by a What3WordsV3 instance. It will act as a factory for all of the API endpoints and will automatically initialize them with your API key.

To obtain an API key, please visit https://what3words.com/select-plan and sign up for an account.

Installation #

The artifact is available through pub.dev. Update your pubspec.yaml file with

dependencies:
 what3words: 3.0.0
copied to clipboard

Documentation #

See the what3words public API documentation

Usage #

Import #

Import the what3words library

import 'package:what3words/what3words.dart';
copied to clipboard

Initialise #

Use the following code with your API key to initialize the API:

var api = What3WordsV3('what3words-api-key');
copied to clipboard

In the case that you run our Enterprise Suite API Server yourself, you may specifty the URL to your own server like so:

var api = What3WordsV3.withEndpoint(
    'what3words-api-key', 
    'https://api.yourserver.com');
copied to clipboard

Additionally, if you run the Enterprise Suite API Server there is another named constructor to support this. Use this if you need to send custom headers to your own server:

var api = What3WordsV3.withHeaders(
      'what3words-api-key', 
      'https://api.yourserver.com',
      {'x-header-1': 'value-1', 'x-header-2': 'value-2'});
copied to clipboard

Example convert to coordinates #

// For all requests a what3words API key is needed
var api = What3WordsV3('what3words-api-key');

// Create and execute a request to obtain a grid section within the provided bounding box
var coordinates = await api.convertToCoordinates('index.home.raft').execute();

if (coordinates.isSuccessful()) {
  print('Coordinates ${coordinates.toJson()}');
} else {
  var error = coordinates.getError();

  if (error == What3WordsError.BAD_WORDS) {
    // The three word address provided is invalid
    print('BadWords: ${error.message}');
  } else if (error == What3WordsError.INTERNAL_SERVER_ERROR) {
    // Server Error
    print('InternalServerError: ${error.message}');
  } else if (error == What3WordsError.NETWORK_ERROR) {
    // Network Error
    print('NetworkError: ${error.message}');
  } else {
    print('${error.code} : ${error.message}');
  }
}
copied to clipboard
10
likes
0
points
1.51k
downloads

Publisher

verified publisherwhat3words.com

Weekly Downloads

2024.09.21 - 2025.04.05

A Dart library to use the what3words v3 API.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

chopper, json_annotation, json_serializable

More

Packages that depend on what3words