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.
- 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
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
- Dart SDK (v2.19.0 or higher)
- Google Places API Key
- Internet connection
-
Clone or download the project
cd integration_google_places_api -
Install dependencies
dart pub get
-
Configure API Key
- Create a
.envfile in the project root - Add your Google Places API key:
GOOGLE_PLACES_API_KEY="your_api_key_here"
- Create a
Run the main application with all default search queries:
dart run lib/main.dartThis will:
- Execute all predefined search queries
- Fetch results from Google Places API with pagination
- Create/append to
places.csvwith all downloaded data - Generate
places_cleaned.csvwith duplicates removed - Display statistics for each step
If you have an existing places.csv and want to regenerate the cleaned version:
dart run lib/remove_duplicates.dartThis creates places_cleaned.csv based on current places.csv
dart run lib/main.dartThis will:
- Execute all predefined search queries
- Fetch results from Google Places API with pagination
- Export results to
places.csv - Remove any duplicate entries
If you have an existing CSV file and want to remove duplicates:
dart run lib/remove_duplicates.dartEdit the main() function in lib/main.dart to modify search queries:
for (String query in [
]) {
await searchPlaces(query, apiKey);
}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
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
| 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" |
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
- 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:
http: ^1.1.0
dotenv: ^3.0.0- http: HTTP client for API requests
- dotenv: Environment variable management
The application includes error handling for:
- Missing or invalid API key
- Network errors
- API response errors
- File I/O errors
- Empty or missing files
- The
.envfile is ignored in.gitignorefor 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
- Ensure
.envfile exists in the project root - Verify the API key is set correctly:
GOOGLE_PLACES_API_KEY=your_key
- Make sure to run commands from the project root directory
- Verify all files are in the correct locations
- Run
dart run lib/remove_duplicates.dartto clean the file - This is automatically called at the end of main search
- 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
For more information about Google Places API Text Search, visit: Google Places API Text Search Documentation
This project is provided as-is for integration and learning purposes.
For issues or questions about this integration, please refer to the Google Places API documentation or create an issue in the project repository.
