How to get started with new Gemini model capabilities for Places API

Google Cloud announced the release of the new Gemini model capabilities for the Places API. 

In addition to using rich information about more than 250 million businesses and places–like ratings, reviews and business hours–developers will also be able to show helpful, generative AI summaries of places and geographic areas right in their own apps and websites. Updated frequently, these summaries use the Gemini model to analyze the place information and insights from Google Maps’ community of over 300 million contributors–helping you display the most up-to-date information possible. 

Specifically, the new Gemini model capabilities for Places API allow developers to display:

Another update to the Places API is AI-powered contextual search results. When users search for places in your products, you’ll now be able to display reviews and photos related to their search, to help them more easily compare places and make decisions.

Users can more easily find and select restaurants with place summaries
Summarize places close to EV charging stations with area summaries, in this fictional example
Provide more relevant reviews and photos with contextual search results, in this fictional example

How to get started?

To get started with the Gemini model capabilities, make sure  you’ve enabled the Places API (New) in your Google Cloud project. Then, include the relevant fields in the field mask of your Place Details, Text Search, or Nearby Search requests. For example:

Below is the python code we will be using to retrieve results throughout the rest of this post. Additional documentation can be found on our developer site.

import requests
import json

API_KEY = "YOUR_API_KEY"
url = "https://places.googleapis.com/v1/places:searchText"

def get_summaries:
    payload = json.dumps({
    "textQuery": query,
    "location_bias": {
        "rectangle": {
            "low": {
                "latitude": 37.415,
                "longitude": -122.091
            },
            "high": {
                "latitude": 37.429,
                "longitude": -122.065
            }
        }
    },
    "maxResultCount": 5
    })
    headers = {
    'Content-Type': 'application/json',
    'X-Goog-Api-Key': API_KEY,
    'X-Goog-FieldMask': 'places.id,places.displayName,contextualContents,places.generativeSummary,places.areaSummary'
    }

    response = requests.request("POST", url, headers=headers, data=payload)
    # the places and context data come in seperate arrays, 
    # it's useful to match them up for easier processing. 
    zipped = zip(response.json()['places'], response.json()['contextualContents'])
    return zipped

Copied to clipboard!

Help your users discover the ideal places with generative place summaries

Generative place summaries provide concise overviews and detailed descriptions that capture the essence and personality of a location.

GenerativeSummary { 
      overview: {
            text: "Popular spot for upscale Italian cuisine,
            including housemade pasta, in a warm, inviting
            atmosphere."
      }
      description: { 
            text: "Upscale Italian restaurant in the Danville Livery
            Shopping Center offering fresh, housemade pasta for
            dine-in and takeout.

            Menu highlights include ravioli, chitarra, lasagna,
            and chicken. The drinks menu features beer, wine, and
            cocktails. There are also happy hour drinks.

            Open for brunch, lunch, and dinner, the cozy
            restaurant offers a market area, a fireplace, and a
            patio. It's a good place for kids, and can accommodate
            parties. People say the service is great."
     }
     references: {...}
}     

Copied to clipboard!

Imagine you’re looking for a restaurant for a special occasion. Instead of just seeing the address and cuisine type, you can now access:

The code to access generative place summaries looks like this:

zipped_response = get_summaries("date night restaurants")

for place, context in zipped_response:
    print(f"-*- {place['displayName']['text']} -*-")
    if "generativeSummary" in place:
        if "overview" in place["generativeSummary"]:
            print(place["generativeSummary"]["overview"]["text"])
        print()
        if "description" in place["generativeSummary"]:
            print(place["generativeSummary"]["description"]["text"])
    else:
        print("No generative summary")
    print()

Copied to clipboard!

Highlight activities in a geographic area with new area summaries

These summaries describe the neighborhood, highlighting nearby dining, shopping, activities, and other points of interest, along with links to relevant places. This feature is ideal for travelers, users exploring new locations, or drivers who use EV charging stations.

The code provides the textual description in the content attribute and the places referenced are found in the places array, in case you want to render them on the page like seen here.

zipped_response = get_summaries("EV charging stations")

for place, context in zipped_response:
    print(place["displayName"]["text"])
    if "areaSummary" in place:
        for block in place["areaSummary"]["contentBlocks"]:
            print(f"--- {block['topic']} ---")
            print(block["content"]["text"])
            if "references" in block:
                for place in block["references"]["places"]:
                    print(f"\t{place}")
            print()

Copied to clipboard!

Provide more relevant reviews and photos with contextual search results

Another update to the Places API is AI-powered contextual search results. When users search for places in your products, you’ll now be able to display reviews and photos related to their search, to help them more easily compare places and make decisions.

For example, if a  user searches for “bars with an ocean view,” photos from the ContextualContent object improve search results by providing visuals and ambiance information relevant to the query.

Beach Chalet Brewery and Restaurant
Zelda’s Coffee Bar

ContextualContent delivers relevant reviews in both full length format as well as a smaller snippet style to meet different user experience needs.

The short form gives you a snippet of the full review that touches on the relevant aspects of the query and includes data on what words to highlight.

Full results are also included. Here is an example of how to parse over the ContextualContent data.

zipped_response = get_summaries("bars with an ocean view")

for place, context in zipped_response:
    print(place["displayName"]["text"])
    print()
    for photo in context["photos"]:
        print(f"https://places.googleapis.com/v1/{photo['name']}/media?maxWidthPx=4800&maxHeightPx=4800&key={API_KEY}")
    print()
    for justification in context["justifications"]:
        if "reviewJustification" in justification:
            snippet = justification["reviewJustification"]["highlightedText"]["text"]
            author = justification["reviewJustification"]["review"]["authorAttribution"]["displayName"]
            print(f"{snippet} -- {author}")
    print()
    if "reviews" in context:
        for review in context["reviews"]:
            print(f"{review['text']['text']}\n-- {review['authorAttribution']['displayName']}")
            print()

Copied to clipboard!

Build the Future of Location-Based Experiences

The Gemini model capabilities for Places API represent an exciting enhancement of the Places API’s location-based experiences. Google Cloud encourage developers to experiment with these features, and Google Cloud can’t wait to see what you build!

Related posts

Steps for Migrating Existing Applications to Microservices

by Cloud Ace Indonesia
3 years ago

Secure and privacy-centric sharing with data clean rooms in BigQuery

by Cloud Ace Indonesia
2 years ago

Learn how to stream JSON data into BigQuery using the new BigQuery Storage Write API

by Kartika Triyanti
3 years ago