Skip to content

MyCyberCodeSpace/integration_google_places_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Places API Integration

A Dart application that integrates with the Google Places API to search for places and export results to CSV format with automatic duplicate removal. Perfect for data collection, lead generation, and business research.

Features

  • Text Search Integration: Search places using text queries via Google Places API
  • Pagination Support: Automatically fetch all available results (up to 60) with page-by-page iteration
  • CSV Export: Export search results with automatic append mode to prevent data loss
    • places.csv - Original downloaded data (complete with all search terms)
    • places_cleaned.csv - Cleaned data with duplicates removed
  • Smart Duplicate Removal: Remove duplicates while ignoring search term differences (keeps first occurrence)
  • Multiple Queries: Execute multiple search queries sequentially with a single run
  • Detailed Results: Capture place information including:
    • Search Term Used
    • Name
    • Phone Number
    • Website URI
    • Rating (0.0 - 5.0 scale)
    • Number of User Reviews
    • Formatted Address

Use Case

This project is ideal for anyone who needs to:

  • Collect business data and lead information at scale
  • Research competitors and market opportunities
  • Gather professional contact information
  • Analyze location-based business data
  • Export structured data for further analysis

Prerequisites

  • Dart SDK (v2.19.0 or higher)
  • Google Places API Key
  • Internet connection

Installation

  1. Clone or download the project

    cd integration_google_places_api
  2. Install dependencies

    dart pub get
  3. Configure API Key

    • Create a .env file in the project root
    • Add your Google Places API key:
      GOOGLE_PLACES_API_KEY="your_api_key_here"
      

Usage

Basic Usage

Run the main application with all default search queries:

dart run lib/main.dart

This will:

  1. Execute all predefined search queries
  2. Fetch results from Google Places API with pagination
  3. Create/append to places.csv with all downloaded data
  4. Generate places_cleaned.csv with duplicates removed
  5. Display statistics for each step

Remove Duplicates Only

If you have an existing places.csv and want to regenerate the cleaned version:

dart run lib/remove_duplicates.dart

This creates places_cleaned.csv based on current places.csv

dart run lib/main.dart

This will:

  1. Execute all predefined search queries
  2. Fetch results from Google Places API with pagination
  3. Export results to places.csv
  4. Remove any duplicate entries

Remove Duplicates Only

If you have an existing CSV file and want to remove duplicates:

dart run lib/remove_duplicates.dart

Customizing Searches

Edit the main() function in lib/main.dart to modify search queries:

for (String query in [

]) {
  await searchPlaces(query, apiKey);
}

Project Structure

integration_google_places_api/
├── lib/
│   ├── main.dart                    # Main application with search logic
│   └── remove_duplicates.dart       # Duplicate removal utility
├── .env                             # Environment variables (not in git)
├── .gitignore                       # Git ignore configuration
├── pubspec.yaml                     # Project dependencies
├── pubspec.lock                     # Dependency lock file
├── places.csv                       # Original downloaded data
├── places_cleaned.csv               # Cleaned data (no duplicates)
└── README.md                        # This file

CSV Output Format

Files Generated

The application creates two CSV files:

places.csv - Original Data

  • Contains all data downloaded from Google Places API
  • Preserves all search terms for traceability
  • Used as source for cleaning process

places_cleaned.csv - Cleaned Data

  • Duplicates removed (ignoring search term differences)
  • Ready for analysis and research
  • Smaller file size for easier filtering

Columns

Column Description Example
Search Term Search query used "Search query user"
Name Business/Place name "Business name"
Phone National phone number "+55 99 9999 9999"
Website Website URL "https://example.com"
Rating User rating "4.8"
Reviews Number of reviews "245"
Address Full formatted address "Rua exemplo, 123"

Example Output

Exemple

API Configuration

Requested Fields (FieldMask)

The application requests these fields from Google Places API for cost efficiency:

places.displayName
places.formattedAddress
places.nationalPhoneNumber
places.websiteUri
places.userRatingCount
places.rating
nextPageToken

Pagination Details

  • Page Size: 20 results per page (API maximum)
  • Max Total Results: 60 per query (API limit)
  • Automatic Iteration: Continues until no more results available
  • Append Mode: Prevents data loss on subsequent runs

Dependencies

dependencies:
  http: ^1.1.0
  dotenv: ^3.0.0
  • http: HTTP client for API requests
  • dotenv: Environment variable management

Error Handling

The application includes error handling for:

  • Missing or invalid API key
  • Network errors
  • API response errors
  • File I/O errors
  • Empty or missing files

Important Notes

  • The .env file is ignored in .gitignore for security
  • Never commit your API key to version control
  • CSV files support append mode to prevent data loss on subsequent runs
  • All duplicate entries are removed while maintaining the first occurrence

Troubleshooting

"GOOGLE_PLACES_API_KEY not configured"

  • Ensure .env file exists in the project root
  • Verify the API key is set correctly: GOOGLE_PLACES_API_KEY=your_key

"No such file or directory"

  • Make sure to run commands from the project root directory
  • Verify all files are in the correct locations

Duplicate entries in CSV

  • Run dart run lib/remove_duplicates.dart to clean the file
  • This is automatically called at the end of main search

No results returned

  • Verify your Google Places API key is valid
  • Check if the API is enabled in your Google Cloud Console
  • Ensure the search query is valid and specific enough

API Documentation

For more information about Google Places API Text Search, visit: Google Places API Text Search Documentation

License

This project is provided as-is for integration and learning purposes.

Support

For issues or questions about this integration, please refer to the Google Places API documentation or create an issue in the project repository.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages