This project fetches details about places (hotels) within France using the Google Maps API and saves the results to an Excel file. It splits France's geographical area into a grid and queries the Google Maps API for each grid point to ensure comprehensive coverage. The results include place names, addresses, phone numbers, and websites.
Before you begin, ensure you have met the following requirements:
- Python 3.x installed on your local machine.
- Necessary Python packages installed (see below).
- A Google Maps API key.
- A GeoJSON file containing France's borders.
You can install the required packages using pip:
pip install googlemaps openpyxl rich shapelyYou need to have a valid Google Maps API key. You can obtain one by following the instructions at Google Cloud Platform.
You need a GeoJSON file containing the geographical borders of France. Ensure this file is accurate and correctly formatted.
- Clone the repository or download the script to your local machine.
- Place your GeoJSON file in the project directory and update the
GEOJSON_FILE_PATHvariable in the script with the correct path. - Update the
API_KEYvariable in the script with your Google Maps API key.
- Run the script:
python script_name.py- The script will load the GeoJSON file, generate grid coordinates, and query the Google Maps API for each grid point to fetch details about hotels.
- The results will be saved to an Excel file named
hotel_in_France.xlsx.
API_KEY: Your Google Maps API key.GEOJSON_FILE_PATH: Path to your GeoJSON file containing France's borders.NUM_GRIDS: Number of grids to split the bounding box into.MAX_REQUESTS_PER_DAY: Maximum number of API requests allowed per day.MAX_REQUESTS_PER_MINUTE: Maximum number of API requests allowed per minute.query: Type of place to search for (e.g., "hotel").radius: Radius for the search around each grid point.
The script imports necessary libraries such as googlemaps, time, openpyxl, rich, datetime, timedelta, shapely, json, and os.
A rich console is initialized for better terminal output.
console = Console()The script loads France borders from a GeoJSON file.
GEOJSON_FILE_PATH = 'path_to_france_geojson.geojson'The script sets the number of grids to split the bounding box into.
NUM_GRIDS = 10000The script defines the maximum number of API requests allowed per day and per minute.
MAX_REQUESTS_PER_DAY = 500000
MAX_REQUESTS_PER_MINUTE = 2000Creates an Excel file from the data.
Fetches details for a place ID.
Fetches places for a given location and radius.
Generates grid coordinates within the borders.
Saves the data to an Excel file and prompts the user to continue or stop.
The main() function initializes the process, generates grid coordinates, fetches data for each grid point, and saves the results to an Excel file.
if __name__ == "__main__":
main()If you want to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes and commit them (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature-branch). - Create a new Pull Request.