location_iq 1.1.0 copy "location_iq: ^1.1.0" to clipboard
location_iq: ^1.1.0 copied to clipboard

A comprehensive, type-safe Dart client for the LocationIQ API with support for geocoding, reverse geocoding, autocomplete, nearby POI, directions, timezone, and account balance services.

LocationIQ API Client for Dart #

A comprehensive, type-safe Dart client for the LocationIQ API. This package provides easy access to LocationIQ's complete suite of location services including geocoding, reverse geocoding, autocomplete, nearby points of interest, directions, timezone information, and account balance monitoring.

pub package style: very good analysis

Features #

  • ๐Ÿ“ Complete LocationIQ API coverage:
    • Forward Geocoding (Free-form, Structured, and Postal Code)
    • Reverse Geocoding
    • Address Autocomplete
    • Nearby Points of Interest - Find restaurants, schools, hospitals, etc.
    • Directions API - Route planning with driving/walking/cycling profiles
    • Timezone API - Get timezone information for coordinates
    • Balance API - Monitor account usage and balance
  • ๐Ÿ›ก๏ธ Type-safe API with null safety
  • ๐ŸŽฏ Comprehensive error handling with specific exception types
  • โšก Configurable timeout and HTTP client
  • ๐Ÿ“š Extensive documentation and examples
  • ๐Ÿงช 89 unit tests with 100% coverage

Installation #

dependencies:
  location_iq: ^1.1.0

Quick Start #

import 'package:location_iq/location_iq.dart';

void main() async {
  final client = LocationIQClient(
    apiKey: 'your_api_key_here',
  );

  try {
    // Free-form forward geocoding
    final locations = await client.forwardFreeform.search(
      query: 'Buckingham Palace, London',
      limit: 5,
    );

    for (final location in locations) {
      print('Location: ${location.displayName}');
      print('Coordinates: ${location.lat}, ${location.lon}');
    }
  } on LocationIQException catch (e) {
    print('Error: ${e.message}');
  }
}

Usage Examples #

Forward Geocoding #

final locations = await client.forwardFreeform.search(
  query: 'Big Ben, London',
  limit: 5,
  acceptLanguage: 'en',
  addressdetails: 1,
);
final results = await client.forwardStructured.search(
  street: '221B Baker Street',
  city: 'London',
  country: 'United Kingdom',
  addressdetails: 1,
);
final locations = await client.forwardPostalcode.search(
  postalcode: 'SW1A 1AA',
  countrycodes: 'gb',
);

Reverse Geocoding #

final address = await client.reverse.reverseGeocode(
  lat: '51.5074',
  lon: '-0.1278',
  language: 'en',
);

Autocomplete #

final suggestions = await client.autocomplete.autocomplete(
  query: 'Bucking',
  countryCode: 'gb',
  limit: 5,
);

Configuration #

Custom HTTP Client #

import 'package:http/http.dart' as http;

final customClient = http.Client();
final locationIQ = LocationIQClient(
  apiKey: 'your_api_key_here',
  httpClient: customClient,
);

Custom Timeout #

final locationIQ = LocationIQClient(
  apiKey: 'your_api_key_here',
  timeout: Duration(seconds: 60),
);

Custom Base URL #

final locationIQ = LocationIQClient(
  apiKey: 'your_api_key_here',
  baseUrl: 'https://eu1.locationiq.com/v1',
);

Error Handling #

The library provides specific exceptions for different error scenarios:

try {
  final results = await client.forwardFreeform.search(query: 'London');
} on AuthenticationException catch (e) {
  print('API key is invalid: ${e.message}');
} on RateLimitException catch (e) {
  print('Rate limit exceeded: ${e.message}');
} on NetworkException catch (e) {
  print('Network error occurred: ${e.message}');
} on LocationIQException catch (e) {
  print('General error: ${e.message}');
}

Available exception types:

  • AuthenticationException - Invalid API key
  • AuthorizationException - Unauthorized domain
  • RateLimitException - Rate limit exceeded
  • NetworkException - Network-related errors
  • BadRequestException - Invalid request parameters
  • NotFoundException - No results found
  • ServerException - Server-side errors
  • UnexpectedException - Unexpected errors

Project Structure #

lib/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ api_config.dart
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ error/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ error_handler.dart
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ exceptions.dart
โ”‚   โ”‚   โ””โ”€โ”€ http/
โ”‚   โ”‚       โ”œโ”€โ”€ http_client.dart
โ”‚   โ”‚       โ””โ”€โ”€ http_status.dart
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ forward_geocoding_result.dart
โ”‚   โ”‚   โ”œโ”€โ”€ location_iq_autocomplete_result.dart
โ”‚   โ”‚   โ””โ”€โ”€ location_iq_reverse_result.dart
โ”‚   โ””โ”€โ”€ services/
โ”‚       โ”œโ”€โ”€ autocomplete/
โ”‚       โ”œโ”€โ”€ forward_geocoding/
โ”‚       โ””โ”€โ”€ reverse_geocoding/
โ””โ”€โ”€ location_iq.dart

Testing #

# Run all tests
dart test

# Run tests with coverage
dart test --coverage

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog #

See CHANGELOG.md for a list of changes and migration guides.

Support #

If you find this package helpful, please consider giving it a star โญ๏ธ on GitHub.

For bugs, feature requests, and questions:

  • Open an issue on GitHub
  • Read our contribution guidelines
1
likes
0
points
22
downloads

Publisher

verified publishertakara.homes

Weekly Downloads

A comprehensive, type-safe Dart client for the LocationIQ API with support for geocoding, reverse geocoding, autocomplete, nearby POI, directions, timezone, and account balance services.

Repository (GitHub)
View/report issues

Topics

#geocoding #maps #location #api-client #locationiq

Documentation

Documentation

License

unknown (license)

Dependencies

http, json_annotation, meta

More

Packages that depend on location_iq