country_coordinates 1.0.0 copy "country_coordinates: ^1.0.0" to clipboard
country_coordinates: ^1.0.0 copied to clipboard

retracted[pending analysis]

A simple package to get coordinates and geometry type of countries.

example/country_coordinates_example.dart

import 'package:country_coordinates/country_coordinates.dart';

void main() async {
  print('🌍 Country Coordinates Package Example\n');

  try {
    // Step 1: Load countries data from assets
    print('πŸ“₯ Loading countries data...');
    await loadCountries();
    print('βœ… Countries data loaded successfully!\n');

    // Step 2: Get all countries and show some basic info
    print('πŸ“‹ Getting all countries...');
    List<Country> allCountries = getAllCountries();
    print('πŸ“Š Total countries available: ${allCountries.length}\n');

    // Step 3: Display first 5 countries as examples
    print('πŸ” First 5 countries:');
    for (int i = 0; i < 5 && i < allCountries.length; i++) {
      Country country = allCountries[i];
      print('  ${i + 1}. ${country.title}');
      print(
          '     Coordinates: [${country.coordinates[0].toStringAsFixed(4)}, ${country.coordinates[1].toStringAsFixed(4)}]');
      print('     Geometry Type: ${country.geometryType}');
      print('');
    }

    // Step 4: Search for specific countries by name
    print('πŸ”Ž Searching for specific countries...\n');

    // Search for France
    Country? france = getCountryByName('France');
    if (france != null) {
      print('πŸ‡«πŸ‡· Found France:');
      print(
          '   Coordinates: [${france.coordinates[0].toStringAsFixed(4)}, ${france.coordinates[1].toStringAsFixed(4)}]');
      print('   Geometry Type: ${france.geometryType}');
      print('');
    } else {
      print('❌ France not found');
    }

    // Search for Japan
    Country? japan = getCountryByName('Japan');
    if (japan != null) {
      print('πŸ‡―πŸ‡΅ Found Japan:');
      print(
          '   Coordinates: [${japan.coordinates[0].toStringAsFixed(4)}, ${japan.coordinates[1].toStringAsFixed(4)}]');
      print('   Geometry Type: ${japan.geometryType}');
      print('');
    } else {
      print('❌ Japan not found');
    }

    // Search for a non-existent country
    Country? nonExistent = getCountryByName('Atlantis');
    if (nonExistent != null) {
      print('🏝️ Found Atlantis: ${nonExistent.title}');
    } else {
      print('❌ Atlantis not found (as expected)');
    }
    print('');

    // Step 5: Demonstrate working with country data
    print('πŸ› οΈ Working with country data...\n');

    Country? usa = getCountryByName('United States');
    if (usa != null) {
      print('πŸ‡ΊπŸ‡Έ United States Details:');
      print('   Name: ${usa.title}');
      print('   Longitude: ${usa.coordinates[0].toStringAsFixed(4)}Β°');
      print('   Latitude: ${usa.coordinates[1].toStringAsFixed(4)}Β°');
      print('   Geometry Type: ${usa.geometryType}');

      // Calculate distance from equator (simple example)
      double distanceFromEquator =
          (usa.coordinates[1] * 111).abs(); // Rough km calculation
      print(
          '   Approximate distance from equator: ${distanceFromEquator.toStringAsFixed(0)} km');
      print('');
    }

    // Step 6: Show some statistics
    print('πŸ“ˆ Package Statistics:');
    print('   β€’ Total countries: ${allCountries.length}');

    // Count different geometry types
    Map<String, int> geometryCounts = {};
    for (Country country in allCountries) {
      geometryCounts[country.geometryType] =
          (geometryCounts[country.geometryType] ?? 0) + 1;
    }

    print('   β€’ Geometry types:');
    geometryCounts.forEach((type, count) {
      print('     - $type: $count countries');
    });

    // Find countries with extreme coordinates
    Country? northernmost = allCountries
        .reduce((a, b) => a.coordinates[1] > b.coordinates[1] ? a : b);
    Country? southernmost = allCountries
        .reduce((a, b) => a.coordinates[1] < b.coordinates[1] ? a : b);
    Country? easternmost = allCountries
        .reduce((a, b) => a.coordinates[0] > b.coordinates[0] ? a : b);
    Country? westernmost = allCountries
        .reduce((a, b) => a.coordinates[0] < b.coordinates[0] ? a : b);

    print('   β€’ Extreme coordinates:');
    print(
        '     - Northernmost: ${northernmost.title} (${northernmost.coordinates[1].toStringAsFixed(2)}Β°)');
    print(
        '     - Southernmost: ${southernmost.title} (${southernmost.coordinates[1].toStringAsFixed(2)}Β°)');
    print(
        '     - Easternmost: ${easternmost.title} (${easternmost.coordinates[0].toStringAsFixed(2)}Β°)');
    print(
        '     - Westernmost: ${westernmost.title} (${westernmost.coordinates[0].toStringAsFixed(2)}Β°)');

    print('\nπŸŽ‰ Example completed successfully!');
    print('πŸ’‘ You can now use these functions in your own projects.');
  } catch (e) {
    print('❌ Error occurred: $e');
    print(
        'πŸ’‘ Make sure the countries.json file is properly included in your assets.');
  }
}
0
likes
0
points
53
downloads

Publisher

unverified uploader

Weekly Downloads

A simple package to get coordinates and geometry type of countries.

Repository (GitHub)
View/report issues

License

(pending) (license)

More

Packages that depend on country_coordinates