Skip to content

SDKs · Flutter

Step 8 — API calls & errors

Geocoding, reverse geocoding, routing, and error handling.

Call the API

Typed API calls
final client = UbHubGeo(apiKey: apiKey);
try {
  final places = await client.geocoding.search('Sukhbaatar Square', limit: 5);
  final nearest = await client.geocoding.reverse(
    location: const GeoPoint(latitude: 47.9184, longitude: 106.9177),
  );
  final result = await client.routing.route(
    origin: const GeoPoint(latitude: 47.9184, longitude: 106.9177),
    destination: const GeoPoint(latitude: 47.9220, longitude: 106.9057),
    mode: TravelMode.driving,
  );
} finally {
  client.close();
}

GeoPoint uses named latitude and longitude; GeoJSON arrays are longitude first. Distances are meters, durations seconds.

Handle errors

Errors and request IDs
try {
  final result = await client.geocoding.search('Ulaanbaatar');
} on RateLimitException catch (error) {
  // error.retryAfter is nullable; defer another request when provided.
} on UbHubException catch (error) {
  // Show error.message; keep error.requestId for support.
}

Typed exceptions extend UbHubException. Invalid local arguments throw ArgumentError. Requests do not retry; respect retryAfter.