arrow_back

Develop GenAI Apps with Gemini and Google Maps

Sign in Join
Get access to 700+ labs and courses

Develop GenAI Apps with Gemini and Google Maps

Lab 1 hour 30 minutes universal_currency_alt 5 Credits show_chart Intermediate
info This lab may incorporate AI tools to support your learning.
Get access to 700+ labs and courses

GSP790

Overview

Vertex AI Studio is a tool for prototyping and customizing generative AI models. Vertex AI offers access to Gemini multimodal models from Google, which are capable of understanding virtually any input, combining different types of information, and generating almost any output.

You are an Application Developer and/or DevOps Engineer for a Travel and Entertainment company. The company hires you to build, and test proof of concept code snippets for an upcoming Travel Agent app that's built on the Gemini Pro model, the Vertex AI Python SDK, and the Google Maps API.

In this lab, you assist the travel agency to provide improved hotel recommendations through chat. To that end, this lab provides an app that uses Gemini and the Google Maps API to provide prompt responses to recommend hotels and nearby restaurants. You review the provided script, enable the Google Maps API, and then use prompts to test the script.

Objectives

In this lab, you learn how to perform the following tasks:

  • Enable the Google Maps API.
  • Install the Vertex AI SDK and Python libraries.
  • Update a pre-written script to access the Google Maps API.
  • Use the Google Maps API to provide hotel and restaurant recommendations.
  • Use prompts to test the script and retrieve travel-related information.

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.

This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details pane.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details pane.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field.

Task 1. Enable the Google Maps API and create the API key

Enable the API

Google Maps API retrieves detailed information about hotels and restaurants. Perform the steps that follow to enable the Google Maps API:

  1. In the Google Cloud console, on the Navigation menu (), click Google Maps Platform.

  2. In the Learn map-making essentials section, click the Enable APIs tab.

  3. In the Finish setup section, click Enable APIs.

When a Preview APIs button displays, this means all necessary APIs are enabled.

Note: You may need to wait a few minutes for this change to take effect to have this objective verified as complete.

Click Check my progress to verify the objective. Enable the Google Maps API

Create the Google Maps API key

Perform the steps that follow to create an API key so your app can access the Google Maps API:

  1. Still in the Google Maps Platform window, click Google Maps Platform (in the upper left), and then Keys & Credentials.

  2. Click Create credentials > API key.

  3. When the API key created window opens, record Your API key to use later in the lab.

  4. Click Close.

Task 2. Set up Vertex AI Workbench for the JupyterLab notebook environment

Open the notebook in Vertex AI Workbench and install the Vertex AI SDK and Python libraries

Open the notebook file in Vertex AI Workbench and then set up your JupyterLab environment.

  1. In the Google Cloud console, on the Navigation menu (), click Vertex AI > Workbench.

  2. Find the instance and click on the Open JupyterLab button.

The JupyterLab interface for your Workbench instance opens in a new browser tab.

  1. The file shows in the explorer (left) pane, double-click to open it.

  2. In the Select Kernel dialog, choose Python 3 from the list of available kernels.

From this point forward, follow the steps in starting at Task 1. Set up Vertex AI Workbench and install the Vertex AI SDK.

Note: The agent-v1.0.0.ipynb notebook file includes instructions on when to return to these lab instructions to Check your progress and score your progress.

Set up Vertex AI Workbench and install the Vertex AI SDK

In this section, you capture the Project ID, region, and Google Maps API key as variables so the values can be used later on in the notebook.

  1. Cell 1 - Update the code as follows:
Content to replace Replace with …
GOOGLE MAPS API KEY <API-key-you recorded earlier>

After you replace the content, the code should be similar to the following:

# Set API_Key to the API key you previously generated. project_id_output = !gcloud config list --format 'value(core.project)' 2>/dev/null PROJECT_ID = project_id_output[0] REGION = !gcloud compute project-info describe --format="value[](commonInstanceMetadata.items.google-compute-default-region)" LOCATION = REGION[0] API_KEY = ""
  1. Run the updated Cell 1, followed by Cell 2, Cell 3, and Cell 4.

You may receive a warning message in red text like the one that follows. This is not an error message and should be ignored because in the case of this lab, Tensorflow is not being used.

2024-03-08 23:15:29.211875: I external/local_tsl/tsl/cuda/cudart_stub.cc:31] Could not find cuda drivers on your machine, GPU will not be used. 2024-03-08 23:15:30.008500: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered 2024-03-08 23:15:30.008663: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered 2024-03-08 23:15:30.155640: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered 2024-03-08 23:15:30.497580: I external/local_tsl/tsl/cuda/cudart_stub.cc:31] Could not find cuda drivers on your machine, GPU will not be used. 2024-03-08 23:15:30.501553: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. 2024-03-08 23:15:37.436150: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT Note: You may need to wait a few minutes to check this task for completion.

Click Check my progress to verify the objective. Install the Vertex AI SDK and Python libraries

Task 3. Use a prompt to get hotel recommendations

Test a prompt using the Python SDK with the Gemini Pro text model

In this task, you review the code included in Task 2 of the notebook, and modify the sample prompt with your custom prompt based upon the requirements specified.

  1. Run Cell 5 and Cell 6.
  2. Cell 7 - A sample prompt is provided. You can optionally modify the travel dates, city and location, and budget. Run the cell.
Note: Major global cities have considerably more Google Maps data to work with based upon customer reviews, photos, etc. Therefore, it's recommended for this prompt that you use a major, global city like Tokyo, New York City, San Francisco, Sydney, etc.
  1. Run Cell 8, Cell 9, Cell 10, and Cell 11.

After running the steps in Task 2 in the notebook file, your output should be a list of hotels, each formatted similar to the following.

Output:


**1. The Trafalgar St. James:**

* Address: 2 Spring Gardens, St. James's, London SW1A  2TS
* Room rate: From £499 per night (approximately $605 USD)
* Distance to Trafalgar Square: 150 meters (2-minute walk)
* Amenities: Free Wi-Fi, restaurant, bar, fitness center, spa
* Website: https://www. thetrafalgarstjames.com/ 

These hotels offer a variety of styles and amenities, all within walking distance of Trafalgar Square and within your budget of $500 per night. 

**Please note:** Prices may vary depending on the specific dates of your stay and availability. 

**Additional options:**

*  Consider using booking websites like Booking.com or Expedia to compare prices and find deals.
* Look into apartment rentals through Airbnb for a more local experience.
* Check out hostels for a budget-friendly option, especially if you are a solo traveler.

I hope this helps you find the perfect hotel for your trip  to London! 


Click Check my progress to verify the objective. Use a prompt to get hotel recommendations

Task 4. Use the Google Maps API to retrieve details about the hotel

Retrieve the geocode data for the Hotel using the Google Maps API

In this task, you save the hotel you want to stay at for your vacation, and use your Google Maps API key to retrieve the geocode results data from Google Maps. You then use this data to retrieve the location and place id.

  1. Cell 12 - Replace INSERT HOTEL NAME HERE with your choice of hotels from the Cell 11 output, and then run the cell. For example:
hotel = 'The Club Quarters Hotel, Trafalgar Square'
  1. Cell 13 - Run the cell. The code should resemble the following:
# Note: API Key is set in cell 1. gmaps = googlemaps.Client(key=API_KEY) # Geocoding an address geocode_result = gmaps.geocode({hotel})
  1. Cell 14 - Run the cell. The output should be similar to the following.

Output:


[{'address_components': [{'long_name': '2',
                          'short_name': '2',
                          'types': ['street_number']},
                         {'long_name': 'Spring Gardens',
                          'short_name': 'Spring Gardens',
                          'types': ['route']},
                         {'long_name': 'Trafalgar Square',
                          'short_name': 'Trafalgar Sq',
                          'types': ['route']},
                         {'long_name': 'London',
                          'short_name': 'London',
                          'types': ['postal_town']},
...
  'formatted_address': '2 Spring Gardens, Trafalgar Sq, London SW1A 2TS, UK',
  'geometry': {'location': {'lat': 51.5073516, 'lng': -0.1291865},
               'location_type': 'ROOFTOP',
               'viewport': {'northeast': {'lat': 51.5086722302915,
                                          'lng': -0.127766569708498},
                            'southwest': {'lat': 51.5059742697085,
                                          'lng': -0.130464530291502}}},
  'navigation_points': [{'location': {'latitude': 51.5073006,
                                      'longitude': -0.1290871}}],
  'partial_match': True,
  'place_id': 'ChIJt2xYKc4EdkgRiSOCe1hI2zU',
  'plus_code': {'compound_code': 'GV4C+W8 London, UK',
                'global_code': '9C3XGV4C+W8'},
  'types': ['establishment', 'lodging', 'point_of_interest']}]

Note: The output uses pprint to display the JSON stored in geocode_result and has been truncated to keep this lab manual brief, but toward the bottom of the output you should notice the place ID for the hotel, which you can retrieve from geocode_result using the code in the following Cell 15.
  1. Cell 15 - Replace INSERT THE KEY FOR THE PLACE ID HERE with the place_id from the Cell 14 output. Don’t forget to include quotes. Run the cell. The resulting code should resemble the following:
for place in geocode_result: place_id = "INSERT THE KEY FOR THE PLACE ID HERE" print(f"Place ID: {place_id}")

You should see the hotel’s Place ID in the output.

Click Check my progress to verify the objective. Use the Google Maps API to retrieve hotel details

Task 5. Use the Google Maps API to retrieve more details about the hotel

Use the place ID to retrieve place details from the Google Maps API

In this task, you use the place ID to retrieve details about the hotel from the maps API. From the results of this function call you retrieve the hotel name (as a confirmation), the hotel address and the international phone number. This information is added to the restaurant recommendation email in a later task. You also retrieve and print the first review for the hotel, and retrieve the URL for all associated photos.

  1. Run Cell 16 and Cell 17.

  2. Review the output of Cell 17, you should see reviews of the hotel.

  3. Cell 18 - Run this cell to retrieve, store, and print the hotel name, the address, and the international phone number. These get added to the restaurant recommendation email in the last task. The code should resemble the following:

hotel_name = data['result']['name'] hotel_address = data['result']['formatted_address'] international_phone_number = data['result']['international_phone_number'] pprint.pprint(hotel_name) pprint.pprint(hotel_address) pprint.pprint(international_phone_number)

The output should be the name, address and international phone number printed with pprint, similar to the following.

Output:


'The Zetter Marylebone'
'28-30 Seymour St, London W1H 7JB, UK'
'+44 20 7324 4544'


  1. Cell 19 - Run the cell to print the first hotel review by using pprint.

    The code should resemble the following:

pprint.pprint(data['result']['reviews'][0])
  1. Run Cell 20 - The code retrieves and prints the Google Maps URL for the hotel, with access to all the photos associated with it, similar to the following result:
['The ' 'Zetter Marylebone']
  1. Save the notebook.
  2. Using your browser, go to the hyperlink provided in the output to Cell 20. You should see all photos associated with the hotel, along with other Google Maps details.

Click Check my progress to verify the objective. Use the Google Maps API to retrieve more details about the hotel

Task 6. Use the Google Maps API to get recommendations for a nearby restaurant

Use the nearby search feature to find a restaurant nearby the hotel

For this task, you use the Google Maps API nearby search feature, the hotel geo-coordinates (latitude and longitude), and the radius parameter to get recommendations for a sushi restaurant nearby the hotel you selected in Task 1.

  1. Cell 21 - Run the cell to save the hotel geo-coordinates as two variables, latitude and longitude.

    You need the latitude and longitude to find nearby locations, like restaurants, in the following cell. The code in the cell should resemble the following:

latitude = data['result']['geometry']['location']['lat'] print(latitude) longitude = data['result']['geometry']['location']['lng'] print(longitude)

And the output should be the coordinates printed.

Output:


51.51487710000001
-0.1586355


  1. Review the Supported Types documentation for the Place API. This link provides place_type parameters you can include in the URL string to specify what you are looking for.

  2. Cell 22 - Run the cell. The code accomplishes the following:

    • From the place_type parameter list, uses sushi_restaurant as the keyword.
    • Use the API key you previously recorded.

    and looks similar to the code below.

url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?keyword=sushi_restaurant&location=" + str(latitude) + "%2C" + str(longitude) + "&radius=500&type=restaurant&key=AIzaSyDTvp3zDCFvkb0AIzYCKT5M0ZPc4FRyL4c" print(url) response = requests.get(url) nearby = response.json()
  1. Run Cell 22 and Cell 23. You should see a JSON response with all sushi restaurants nearby and then the first one within the radius you set.
  2. Run Cell 24. You should see the first restaurant in the list. The output should be similar to the following.

Output:


{'business_status': 'OPERATIONAL',
 'geometry': {'location': {'lat': 51.5192753, 'lng': -0.1628414},
              'viewport': {'northeast': {'lat': 51.52058817989273,
                                         'lng': -0.1614787701072778},
                           'southwest': {'lat': 51.51788852010728,
                                         'lng': -0.1641784298927222}}},
 'icon': 'https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/restaurant-71.png',
 'icon_background_color': '#FF9E67',
 'icon_mask_base_uri': 'https://maps.gstatic.com/mapfiles/place_api/icons/v2/restaurant_pinlet',
 'name': 'The Sushi Co - Marylebone',
 'opening_hours': {'open_now': False},
 'photos': [{'height': 1282,
             'html_attributions': ['A '
                                   'Google User'],
             'photo_reference': 'ATplDJblS0m6KJkY5BBTdzlaqS1DQlC4KReTqWyBtBp3gXahH2eJJVWEGU-VTItBytk-nUZH8EI27BYoRVar2CJBc0jOhkL7nWzDamZtq5vmfUVxrq5-7TFf3ZHrK4Zc2ZiF1JQwthZYPplAzXgmzWk2ROKH0j2ApxM8GjXQYhEsfOY0-OZi',
             'width': 1920}],
 'place_id': 'ChIJUTYMRn8bdkgR86ABd3dNCbM',
 'plus_code': {'compound_code': 'GR9P+PV London', 'global_code': '9C3XGR9P+PV'},
 'rating': 4.7,
 'reference': 'ChIJUTYMRn8bdkgR86ABd3dNCbM',
 'scope': 'GOOGLE',
 'types': ['restaurant', 'food', 'point_of_interest', 'establishment'],
 'user_ratings_total': 197,
 'vicinity': '48 Crawford St, London'}


  1. Run the code in Cell 25 to set the nearby_restaurant variable to the place-id for the restaurant.

    The code should resemble the following:

nearby_restaurant = nearby['results'][0]['place_id'] print(nearby_restaurant)

The output should be a place ID similar to the following output example.

Output:


ChIJUTYMRn8bdkgR86ABd3dNCbM


  1. Run Cell 26 to include the place ID variable for the restaurant you stored in the previous step.

  2. Run Cell 27 and observe the output, which is the Google Maps details of the sushi restaurant.

  3. Run Cell 28 to store the restaurant name, first review, and Google Maps URL for the sushi restaurant.

    The code should resemble the following:

# Review the output from the previous cell. From the restaurant details in `restaurant_data`, Retrieve the restaurant name, first review and map URL for the restaurant, by completing the code below. restaurant_name = restaurant_data['result']['name'] review = restaurant_data['result']['reviews'][0] map_url = restaurant_data['result']['url'] pprint.pprint(restaurant_name) pprint.pprint(review) pprint.pprint(map_url)

The output should resemble the following.

Output:


'The Sushi Co - Marylebone'
{'author_name': 'Griff Hayward',
 'author_url': 'https://www.google.com/maps/contrib/103419765716576164680/reviews',
 'language': 'en',
 'original_language': 'en',
 'profile_photo_url': 'https://lh3.googleusercontent.com/a-/ALV-UjVOPUa51gCmHN5C64Jxf0_D2zx-QULivnjjNTgU_mYJqg=s128-c0x00000000-cc-rp-mo-ba4',
 'rating': 4,
 'relative_time_description': '3 months ago',
 'text': 'Review for the sushi co Kensington, as it wouldn’t let me review '
         'it.\n'
         '\n'
         'The food here was very nice and the staff were helpful and friendly, '
         'however, the service was extremely slow, especially considering that '
         'the restaurant was pretty much empty on a Tuesday evening. The sushi '
         'was very good, but it did feel pretty difficult to order a full meal '
         'as the cheapest actual sushi box with a proper selection was around '
         '£26, although the prices were generally fair. I was told that the '
         'Curries and ramen were underwhelming.\n'
         'Overall, very tasty sushi and a nice setting, but with a very '
         'western feel as far as sushi goes. Very weird that they wouldn’t let '
         'me add photos, so I’ve put the photos for this place on the '
         'Marylebone sight.',
 'time': 1700396289,
 'translated': False}
'https://maps.google.com/?cid=12900927783072538867'


Click Check my progress to verify the objective. Use the Google Maps API to get recommendations for a nearby restaurant

Task 7. Use the Vertex AI API to create an email recommending a nearby restaurant

Create an email recommending a nearby restaurant using the Vertex AI API

For this task, you use Gemini Pro to create a restaurant recommendation email based on details you collected throughout the lab for the hotel and the sushi restaurant, including the following:

  • Hotel name
  • Hotel address
  • Hotel international phone number
  • Restaurant name
  • Restaurant review
  • Google Maps hyperlink for the hotel
  1. Run Cell 28 to use the Gemini Pro GenerativeModel to complete the creation of the model_restaurant model.

    The code should resemble the following:

model_restaurant = GenerativeModel("gemini-pro")
  1. Run Cell 29 and Cell 30.

  2. Run Cell 31 so that the international phone number is included in the resulting email.

    The code should resemble the following:

prompt_email = f"""You are a marketing director for {hotel_name} at {hotel_address} and can be reached at {international_phone_number}. Write an email to a customer suggesting {restaurant_name} as a recommended restaurant near {hotel}, include review information {review} providing another customer's experience and a hyperlink to a google map {map_url}. The email should have an upbeat and positive tone, however do not include the reviewer's name."""
  1. Run Cell 32. Observe the output. You should see an email template created with the details you collected throughout your work in this notebook, including:

    • The hotel name, with the international phone number.
    • The name of the restaurant with a review included.
    • The Google Maps link to the restaurant.

    The output should be similar to the following.

Output:


Your customer email:
Subject: Delightful Dining Recommendation near The Zetter Marylebone

Dear [Customer's name],

We hope you are having a  wonderful stay at The Zetter Marylebone.

For your dining pleasure, we highly recommend The Sushi Co  - Marylebone, just a stone's throw away from the hotel.

This cozy restaurant offers a delectable array of authentic Japanese cuisine, with a special emphasis on fresh and flavorful sushi. One satisfied customer recently shared their experience on Google Maps:

"The food here was  very nice, and the staff were helpful and friendly. The sushi was very good, but it did feel pretty difficult to order a full meal as the cheapest actual sushi box with a proper selection was around £26. Overall, very tasty sushi and a nice setting."

 For further information and to explore the menu, please visit their Google Maps listing here: https://maps.google.com/?cid=12900927783072538867

We believe The Sushi Co - Marylebone is the perfect spot to satisfy your cravings for authentic Japanese flavors.  Please do not hesitate to contact us if you have any questions or require further assistance.

Thank you for choosing The Zetter Marylebone. We hope you have a memorable and enjoyable stay.

Best regards,

[Your name]
Marketing Director
The Zetter Marylebone
+44 20 7324 4544
28-30 Seymour St, London W1H 7JB, UK


Click Check my progress to verify the objective. Create the restaurant recommendation email

Congratulations!

In this lab, you have learned how to develop a GenAI application with Gemini and Google Maps.

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated May 22, 2025

Lab Last Tested May 22, 2025

Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.