This Python project demonstrates how to connect to the Google Maps Geocoding API to retrieve geographical coordinates (latitude and longitude) for a specific address using the requests library. In this project, we provide a simple index.py file that fetches and displays the geocoding data for a predefined address.
Before running this project, ensure you have the following:
- Python installed on your system (at least Python 3.x).
- A Google Cloud Platform (GCP) project with the Google Maps Geocoding API enabled.
- An API key for the Google Maps Geocoding API. You can obtain one by following the Google Maps JavaScript API documentation.
- Clone or download this repository to your local machine.
git clone https://github.com/adanzweig/Python-GoogleGeoCoding.git- Navigate to the project directory.
cd Python-GoogleGeoCoding-
Open the
index.pyfile in your code editor. -
Replace
APIKEYwith your Google Maps Geocoding API key and"1600 Amphitheatre Parkway, Mountain View, CA"with the address you want to geocode.
api_key = "your_api_key_here"
address = "your_address_here"- Save your changes.
To retrieve geographical coordinates for a specific address, follow these steps:
-
Make sure you have set your API key and address in the
index.pyfile as mentioned above. -
Run the project using Python:
python index.py- The geocoding data for the specified address will be displayed in the console.
Here's an example of what the output might look like in the console:
[
{
"address_components": [...],
"formatted_address": "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
"geometry": {
"location": {
"lat": 37.423021,
"lng": -122.083739
},
"location_type": "ROOFTOP",
"viewport": {...}
},
"place_id": "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"plus_code": {...},
"types": ["street_address"]
}
]This project is licensed under the MIT License. Feel free to use, modify, and distribute it as needed. See the LICENSE file for more details.
- Geocoding data is provided by the Google Maps Geocoding API.
- This project uses the
requestslibrary to make HTTP requests.
If you have any questions or encounter issues, please don't hesitate to reach out.
Happy coding!