ubhub_maps 0.2.1 copy "ubhub_maps: ^0.2.1" to clipboard
ubhub_maps: ^0.2.1 copied to clipboard

Official Dart SDK for the UBHUB Geospatial API, with typed geocoding, reverse geocoding, routing, and secure API-key authentication.

example/main.dart

// Run: dart run example/main.dart
// Set UBHUB_API_KEY in your process environment before running.

import 'dart:io';
import 'package:ubhub_maps/ubhub_maps.dart';

Future<void> main() async {
  final key = Platform.environment['UBHUB_API_KEY'];
  if (key == null || key.isEmpty) {
    stderr.writeln('Set UBHUB_API_KEY in the process environment.');
    exitCode = 64;
    return;
  }
  final baseUrl = Platform.environment['UBHUB_BASE_URL'];
  final client = baseUrl == null
      ? UbHubGeo(apiKey: key)
      : UbHubGeo(apiKey: key, baseUrl: baseUrl);
  try {
    await demonstrate(client, write: stdout.writeln);
  } on RateLimitException catch (e) {
    stderr.writeln(
        'Rate limited. Retry after: ${e.retryAfter}. Request: ${e.requestId}');
    exitCode = 1;
  } on UbHubException catch (e) {
    stderr.writeln('${e.message} Request: ${e.requestId}');
    exitCode = 1;
  } finally {
    client.close();
  }
}

/// Runs the three services; injectable output keeps this example testable.
Future<void> demonstrate(UbHubGeo client,
    {required void Function(String) write}) async {
  final places = await client.geocoding.search('Sukhbaatar Square', limit: 5);
  for (final place in places.results) {
    write(
        '${place.name}: ${place.address ?? "No address"} (${place.location})');
  }
  const origin = GeoPoint(latitude: 47.9184, longitude: 106.9177);
  const destination = GeoPoint(latitude: 47.9220, longitude: 106.9057);
  final nearest = await client.geocoding.reverse(location: origin);
  write(nearest.results.isEmpty
      ? 'No nearby address.'
      : 'Nearest: ${nearest.results.first.name}');
  final route =
      await client.routing.route(origin: origin, destination: destination);
  write(
      'Route: ${route.route.distanceMeters} m, ${route.route.durationSeconds} s');
}
0
likes
0
points
581
downloads

Documentation

Documentation

Publisher

verified publisherdevelopers.ubhub.mn

Weekly Downloads

Official Dart SDK for the UBHUB Geospatial API, with typed geocoding, reverse geocoding, routing, and secure API-key authentication.

Homepage
Repository (GitHub)
View/report issues

Topics

#geocoding #routing #geospatial

License

unknown (license)

Dependencies

http

More

Packages that depend on ubhub_maps