getAddress method

Future<ApiResponse<List<MapBoxPlace>?>> getAddress(
  1. Location location
)

Get the address of the given location coordinates

Implementation

Future<ApiResponse<List<MapBoxPlace>?>> getAddress(Location location) async {
  // Assert that if limit is not null then only one type is passed
  assert(limit != null && (types.length == 1) || limit == null,
      'Limit is not null so you can only pass one type');
  Uri uri = _createUrl(location.asString);
  final response = await http.get(uri);

  if (response.statusCode != 200) {
    return (
      success: null,
      failure: FailureResponse.fromJson(json.decode(response.body))
    );
  }

  return (
    success: Predictions.fromJson(json.decode(response.body)).features,
    failure: null
  );
}