Welcome to the "Get Longitude and Latitude from Address using Google Maps API" template. This template is designed to help you quickly set up a FastAPI web server that provides an endpoint to fetch geographical coordinates based on a given address. It's a straightforward and efficient way to integrate location-based services into your applications.
To begin using this template, simply click on the "Start with this Template" button. This will initialize the template in the Lazy Builder interface, pre-populating the code for you.
Before you can use the template, you need to set up an environment secret for the Google Maps API key. Here's how to acquire and set up your API key:
GOOGLE_MAPS_API_KEY
and paste your copied API key as the value.Once you have set up your Google Maps API key in the Environment Secrets, you can test the application by pressing the "Test" button. This will deploy your app and launch the Lazy CLI.
After pressing the "Test" button, the Lazy App's CLI interface will appear. You will be prompted to provide the address for which you want to fetch the coordinates. Enter the address as instructed by the CLI.
After entering the address, the application will process your request and return the latitude and longitude of the specified address. You will receive a server link through the Lazy builder CLI to interact with the API. Additionally, since this template uses FastAPI, you will also be provided with a link to the API documentation, which can be used to explore other available endpoints and their usage.
If you wish to integrate this API into an external service or frontend, you can use the server link provided by Lazy. Here's a sample request you might make to the API:
POST /get_address_coordinates
Content-Type: application/x-www-form-urlencoded
address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
And here's a sample response you might receive:
{
"latitude": 37.4224764,
"longitude": -122.0842499
}
Use the provided server link to send requests from your external service or frontend to fetch coordinates for different addresses. Ensure that you handle user input securely and validate it before sending it to the API.
By following these steps, you can seamlessly integrate the "Get Longitude and Latitude from Address using Google Maps API" template into your application, providing valuable location-based functionalities to your users.