geo_contacts 1.1.1 copy "geo_contacts: ^1.1.1" to clipboard
geo_contacts: ^1.1.1 copied to clipboard

GeoContacts is a Dart package for managing geographical contacts.

example/geo_contacts_example.dart

import 'dart:io';

import 'package:geo_contacts/geo_contacts.dart';

void main() async {
  var geoContacts = GeoContacts(
    apiKey: 'API_KEY',
    maxLimit: 10,
    apiRateLimitDurationMS: 1000,
  );

  //It is a future method that will be called to search for places
  // It takes time based on the [maxLimit] and [apiRateLimitDurationMS]
  final results = await geoContacts.searchPlaces(
    'restaurant',
    'Ganesh Nagar, Delhi',
  );

  // Print the details of each place found in the results
  await for (var partialResults in geoContacts.searchPlacesStream(
    'restaurant',
    'Ganesh Nagar, Delhi',
  )) {
    print('Items: ${partialResults.length}\nData: ${partialResults.last}');
  }

  print(results);

  await _exportToCSV(results, 'restaurant', 'Ganesh Nagar, Delhi');
}

Future<void> _exportToCSV(
  List<GeoContact> data,
  String keyword,
  String city,
) async {
  if (data.isEmpty) {
    print(
      'No data to export. The search did not find any results for "$keyword" in "$city".',
    );
    return;
  }

  final fileName =
      '${keyword}_in_${city.replaceAll(' ', '_').toLowerCase()}.csv';
  final file = File(fileName);
  final sink = file.openWrite();

  // Add headers
  sink.writeln(GeoContact.headers.map((header) => '"$header"').join(','));

  // Add data rows
  for (var row in data) {
    sink.writeln(
      row.toValuesString
          .map((value) {
            // Escape values containing commas by wrapping them in double quotes
            if (value.contains(',')) {
              return '"$value"';
            }
            return value;
          })
          .join(','),
    );
  }

  await sink.flush();
  await sink.close();

  print('\nšŸŽ‰ Done! Exported ${data.length} results to $fileName');
  print('File saved at: ${file.path}');
}
0
likes
150
points
29
downloads

Publisher

verified publisherwaygosquad.com

Weekly Downloads

GeoContacts is a Dart package for managing geographical contacts.

Repository (GitHub)

Topics

#google-places #contacts #geolocation

Documentation

API reference

License

MIT (license)

Dependencies

dio

More

Packages that depend on geo_contacts