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.

Country Coordinates #

A simple and lightweight Dart package to get coordinates and geometry type of countries. This package provides easy access to geographical data for countries around the world.

Features #

  • 🌍 Worldwide Coverage: Access coordinates for countries across all continents
  • 📍 Precise Coordinates: Get latitude and longitude coordinates for each country
  • 🔷 Geometry Types: Understand the geometric representation of each country
  • Lightweight: Minimal dependencies and fast performance
  • 🎯 Easy to Use: Simple API with intuitive methods

Installation #

Add this dependency to your pubspec.yaml file:

dependencies:
  country_coordinates: ^1.0.0

Then run:

dart pub get

Usage #

Basic Setup #

First, ensure your countries.json file is properly included in your assets:

# pubspec.yaml
flutter:
  assets:
    - assets/countries.json

Loading Countries Data #

import 'package:country_coordinates/country_coordinates.dart';

void main() async {
  // Load countries data from assets
  await loadCountries();
  
  // Now you can use the package functions
}

Getting All Countries #

// Get a list of all countries
List<Country> allCountries = getAllCountries();

// Print each country's information
for (Country country in allCountries) {
  print('${country.title}: ${country.coordinates} (${country.geometryType})');
}

Finding a Specific Country #

// Find a country by name (case-insensitive)
Country? france = getCountryByName('France');
if (france != null) {
  print('France coordinates: ${france.coordinates}');
  print('Geometry type: ${france.geometryType}');
}

Working with Country Data #

Country country = getCountryByName('Japan')!;

// Access country properties
String name = country.title;                    // "Japan"
List<double> coords = country.coordinates;     // [longitude, latitude]
String geometry = country.geometryType;        // "Point", "Polygon", etc.

// Use coordinates for mapping or calculations
double longitude = coords[0];
double latitude = coords[1];

API Reference #

Functions #

loadCountries()

Loads countries data from the assets/countries.json file.

  • Returns: Future<List<dynamic>>
  • Usage: Call this function before using other package functions

getAllCountries()

Retrieves a list of all available countries.

  • Returns: List<Country>
  • Usage: Get all countries for iteration or filtering

getCountryByName(String name)

Finds a specific country by name.

  • Parameters: name - The country name to search for (case-insensitive)
  • Returns: Country? - The found country or null if not found
  • Usage: Locate specific countries by name

Country Model #

The Country class contains the following properties:

  • title (String): The name of the country
  • coordinates (List<double>): Array of coordinates [longitude, latitude]
  • geometryType (String): The geometric representation type

Data Format #

The package uses a JSON file (countries.json) with the following structure:

[
  {
    "title": "Country Name",
    "coordinates": [longitude, latitude],
    "geometry_type": "Point"
  }
]

Example Projects #

Flutter Map Integration #

import 'package:flutter_map/flutter_map.dart';
import 'package:country_coordinates/country_coordinates.dart';

class CountryMap extends StatefulWidget {
  @override
  _CountryMapState createState() => _CountryMapState();
}

class _CountryMapState extends State<CountryMap> {
  @override
  void initState() {
    super.initState();
    _loadCountries();
  }

  Future<void> _loadCountries() async {
    await loadCountries();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return FlutterMap(
      options: MapOptions(
        center: LatLng(0, 0),
        zoom: 2,
      ),
      children: [
        TileLayer(
          urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
        ),
        MarkerLayer(
          markers: getAllCountries().map((country) {
            return Marker(
              point: LatLng(
                country.coordinates[1], // latitude
                country.coordinates[0], // longitude
              ),
              builder: (ctx) => Icon(Icons.location_on),
            );
          }).toList(),
        ),
      ],
    );
  }
}

Console Application #

import 'package:country_coordinates/country_coordinates.dart';

void main() async {
  print('Loading countries data...');
  await loadCountries();
  
  print('\nAvailable countries:');
  List<Country> countries = getAllCountries();
  
  for (Country country in countries.take(5)) {
    print('${country.title}: [${country.coordinates[0]}, ${country.coordinates[1]}]');
  }
  
  // Search for a specific country
  Country? searchResult = getCountryByName('Canada');
  if (searchResult != null) {
    print('\nFound Canada:');
    print('Coordinates: ${searchResult.coordinates}');
    print('Geometry Type: ${searchResult.geometryType}');
  }
}

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.

License #

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

Support #

If you encounter any issues or have questions, please:

  1. Check the Issues page
  2. Create a new issue if your problem isn't already reported
  3. Provide detailed information about your environment and the issue you're experiencing

Changelog #

See CHANGELOG.md for a list of changes and version history.


Made with ❤️ for the Dart/Flutter community

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