การอ้างอิงตำแหน่งด้วย Google Maps

การอ้างอิงด้วย Google Maps จะเชื่อมต่อความสามารถในการสร้างของ Gemini กับข้อมูลที่สมบูรณ์ เป็นข้อเท็จจริง และเป็นข้อมูลล่าสุดของ Google Maps ฟีเจอร์นี้ช่วยให้นักพัฒนาแอปผสานรวมฟังก์ชันการทำงานที่รับรู้ตำแหน่งไว้ในแอปพลิเคชันของตนได้อย่างง่ายดาย เมื่อคำค้นหาของผู้ใช้มีบริบทที่เกี่ยวข้องกับข้อมูล Maps โมเดล Gemini จะใช้ประโยชน์จาก Google Maps เพื่อให้คำตอบที่ถูกต้องตามข้อเท็จจริงและเป็นข้อมูลล่าสุด ซึ่ง เกี่ยวข้องกับตำแหน่งที่ผู้ใช้ระบุหรือพื้นที่ทั่วไป

  • คำตอบที่ถูกต้องและรับรู้ตำแหน่ง: ใช้ประโยชน์จากข้อมูลที่ครอบคลุมและเป็นปัจจุบันของ Google Maps สำหรับคำค้นหาที่เจาะจงทางภูมิศาสตร์
  • การปรับตามโปรไฟล์ของผู้ใช้ที่ดียิ่งขึ้น: ปรับแต่งคำแนะนำและข้อมูลตามสถานที่ที่ผู้ใช้ระบุ
  • ข้อมูลและวิดเจ็ตตามบริบท: โทเค็นบริบทเพื่อแสดงวิดเจ็ต Google Maps แบบอินเทอร์แอกทีฟควบคู่ไปกับเนื้อหาที่สร้างขึ้น

เริ่มต้นใช้งาน

ตัวอย่างนี้แสดงวิธีผสานรวมการอ้างอิงกับ Google Maps เข้ากับแอปพลิเคชันของคุณเพื่อแสดงคำตอบที่แม่นยำและรับรู้ตำแหน่งสำหรับคำค้นหาของผู้ใช้ พรอมต์ขอคำแนะนำในพื้นที่พร้อมตำแหน่งของผู้ใช้ (ไม่บังคับ) เพื่อให้โมเดล Gemini ใช้ประโยชน์จากข้อมูล Google Maps ได้

Python

from google import genai
from google.genai import types

client = genai.Client()

prompt = "What are the best Italian restaurants within a 15-minute walk from here?"

response = client.models.generate_content(
    model='gemini-2.5-flash-lite',
    contents=prompt,
    config=types.GenerateContentConfig(
        # Turn on grounding with Google Maps
        tools=[types.Tool(google_maps=types.GoogleMaps())],
        # Optionally provide the relevant location context (this is in Los Angeles)
        tool_config=types.ToolConfig(retrieval_config=types.RetrievalConfig(
            lat_lng=types.LatLng(
                latitude=34.050481, longitude=-118.248526))),
    ),
)

print("Generated Response:")
print(response.text)

if grounding := response.candidates[0].grounding_metadata:
  if grounding.grounding_chunks:
    print('-' * 40)
    print("Sources:")
    for chunk in grounding.grounding_chunks:
      print(f'- [{chunk.maps.title}]({chunk.maps.uri})')

JavaScript

import { GoogleGenAI } from "@google/gnai";

const ai = new GoogleGenAI({});

async function generateContentWithMapsGrounding() {
  const response = await ai.models.generateContent({
    model: "gemini-2.5-flash",
    contents: "What are the best Italian restaurants within a 15-minute walk from here?",
    config: {
      // Turn on grounding with Google Maps
      tools: [{ googleMaps: {} }],
      toolConfig: {
        retrievalConfig: {
          // Optionally provide the relevant location context (this is in Los Angeles)
          latLng: {
            latitude: 34.050481,
            longitude: -118.248526,
          },
        },
      },
    },
  });

  console.log("Generated Response:");
  console.log(response.text);

  const grounding = response.candidates[0]?.groundingMetadata;
  if (grounding?.groundingChunks) {
    console.log("-".repeat(40));
    console.log("Sources:");
    for (const chunk of grounding.groundingChunks) {
      if (chunk.maps) {
        console.log(`- [${chunk.maps.title}](${chunk.maps.uri})`);
      }
    }
  }
}

generateContentWithMapsGrounding();

REST

curl -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent' \
  -H 'Content-Type: application/json' \
  -H "x-goog-api-key: ${GEMINI_API_KEY}" \
  -d '{
  "contents": [{
    "role": "user",
    "parts": [{
      "text": "What are the best Italian restaurants within a 15-minute walk from here?"
    }]
  }],
  "tools": [{"googleMaps": {}}],
  "toolConfig": {
    "retrievalConfig": {
      "latLng": {"latitude": 34.050481, "longitude": -118.248526}
    }
  }
}'

วิธีการทำงานของฟีเจอร์กราวด์ด้วย Google Maps

Grounding with Google Maps ผสานรวม Gemini API กับระบบนิเวศทางภูมิศาสตร์ของ Google โดยใช้ Maps API เป็นแหล่งที่มาของข้อมูลพื้นฐาน เมื่อคำค้นหาของผู้ใช้มีบริบททางภูมิศาสตร์ โมเดล Gemini จะเรียกใช้เครื่องมือการอ้างอิงกับ Google Maps ได้ จากนั้นโมเดลจะสร้างคำตอบโดยอิงตามข้อมูล Google Maps ที่เกี่ยวข้องกับสถานที่ที่ระบุ

โดยปกติแล้วกระบวนการนี้จะมีขั้นตอนต่อไปนี้

  1. คำค้นหาของผู้ใช้: ผู้ใช้ส่งคำค้นหาไปยังแอปพลิเคชันของคุณ ซึ่งอาจรวมถึงบริบททางภูมิศาสตร์ (เช่น "ร้านกาแฟใกล้ฉัน" "พิพิธภัณฑ์ใน ซานฟรานซิสโก")
  2. การเรียกใช้เครื่องมือ: โมเดล Gemini จะเรียกใช้เครื่องมือการอ้างอิงกับ Google Maps เมื่อรับรู้ถึงเจตนาทางภูมิศาสตร์ เครื่องมือนี้อาจมีlatitudeและlongitudeของผู้ใช้เพื่อผลลัพธ์ที่รับรู้ตำแหน่ง
  3. การดึงข้อมูล: บริการ Grounding with Google Maps จะค้นหาข้อมูลที่เกี่ยวข้องใน Google Maps (เช่น สถานที่ รีวิว รูปภาพ ที่อยู่ เวลาทําการ)
  4. การสร้างแบบมีพื้นฐาน: ระบบจะใช้ข้อมูล Maps ที่ดึงมาเพื่อแจ้งคำตอบของโมเดล Gemini เพื่อให้มั่นใจถึงความถูกต้องตามข้อเท็จจริงและความเกี่ยวข้อง
  5. โทเค็นคำตอบและวิดเจ็ต: โมเดลจะแสดงคำตอบเป็นข้อความ ซึ่งมี การอ้างอิงแหล่งที่มาจาก Google Maps นอกจากนี้ การตอบกลับของ API อาจมี google_maps_widget_context_token ด้วย (ไม่บังคับ) ซึ่งช่วยให้นักพัฒนาแอปแสดงวิดเจ็ต Google Maps ตามบริบทในแอปพลิเคชันเพื่อการโต้ตอบด้วยภาพได้

เหตุผลและเวลาที่ควรใช้การอ้างอิงกับ Google Maps

การอ้างอิงกับ Google Maps เหมาะสำหรับแอปพลิเคชันที่ต้องการข้อมูลที่ถูกต้อง เป็นปัจจุบัน และเฉพาะเจาะจงตำแหน่ง โดยจะช่วยยกระดับประสบการณ์ของผู้ใช้ ด้วยการแสดงเนื้อหาที่เกี่ยวข้องและปรับเปลี่ยนในแบบของคุณ ซึ่งขับเคลื่อนโดยฐานข้อมูลขนาดใหญ่ของ Google Maps ที่มีสถานที่กว่า 250 ล้านแห่งทั่วโลก

คุณควรใช้การอ้างอิงกับ Google Maps เมื่อแอปพลิเคชันของคุณต้องการทำสิ่งต่อไปนี้

  • ตอบคำถามที่เฉพาะเจาะจงตามภูมิศาสตร์ให้ถูกต้องสมบูรณ์
  • สร้างเครื่องมือวางแผนการเดินทางและไกด์นำเที่ยวในพื้นที่แบบสนทนา
  • แนะนำจุดที่น่าสนใจตาม ตำแหน่งและความชอบของผู้ใช้ เช่น ร้านอาหารหรือร้านค้า
  • สร้างประสบการณ์ที่รับรู้ตำแหน่งสำหรับบริการโซเชียล การค้าปลีก หรือการนำส่งอาหาร

การอ้างอิงจาก Google Maps เหมาะอย่างยิ่งสำหรับกรณีการใช้งานที่ต้องใช้ข้อมูลความใกล้เคียงและข้อมูลข้อเท็จจริงปัจจุบัน เช่น การค้นหา "ร้านกาแฟที่ดีที่สุดใกล้ฉัน" หรือการขอเส้นทาง

เมธอดและพารามิเตอร์ของ API

การอ้างอิงกับ Google Maps จะแสดงผ่าน Gemini API เป็นเครื่องมือภายในเมธอด generateContent คุณเปิดใช้และกำหนดค่า การอ้างอิงจาก Google Maps ได้โดยการรวมออบเจ็กต์ googleMaps ไว้ในพารามิเตอร์ tools ของคำขอ

JSON

{
  "contents": [{
    "parts": [
      {"text": "Restaurants near Times Square."}
    ]
  }],
  "tools":  { "googleMaps": {} }
}

นอกจากนี้ เครื่องมือ googleMaps ยังยอมรับพารามิเตอร์บูลีน enableWidget ซึ่งใช้เพื่อควบคุมว่าจะแสดงผลฟิลด์ googleMapsWidgetContextToken ในการตอบกลับหรือไม่ ซึ่งใช้เพื่อแสดงวิดเจ็ตสถานที่ตามบริบทได้

JSON

{
"contents": [{
    "parts": [
      {"text": "Restaurants near Times Square."}
    ]
  }],
  "tools":  { "googleMaps": { "enableWidget": true } }
}

นอกจากนี้ เครื่องมือยังรองรับการส่งตำแหน่งตามบริบทเป็น toolConfig

JSON

{
  "contents": [{
    "parts": [
      {"text": "Restaurants near here."}
    ]
  }],
  "tools":  { "googleMaps": {} },
  "toolConfig":  {
    "retrievalConfig": {
      "latLng": {
        "latitude": 40.758896,
        "longitude": -73.985130
      }
    }
  }
}

ทำความเข้าใจการตอบกลับแบบอ้างอิง

เมื่อการตอบกลับอิงตามข้อมูล Google Maps สำเร็จ การตอบกลับจะมีช่อง groundingMetadata ข้อมูลที่มีโครงสร้างนี้มีความสำคัญอย่างยิ่งต่อการยืนยันการอ้างสิทธิ์และการสร้างประสบการณ์การอ้างอิงที่สมบูรณ์ในแอปพลิเคชันของคุณ รวมถึงการปฏิบัติตามข้อกำหนดในการใช้งานบริการ

JSON

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "CanteenM is an American restaurant with..."
          }
        ],
        "role": "model"
      },
      "groundingMetadata": {
        "groundingChunks": [
          {
            "maps": {
              "uri": "https://maps.google.com/?cid=13100894621228039586",
              "title": "Heaven on 7th Marketplace",
              "placeId": "places/ChIJ0-zA1vBZwokRon0fGj-6z7U"
            },
            // repeated ...
          }
        ],
        "groundingSupports": [
          {
            "segment": {
              "startIndex": 0,
              "endIndex": 79,
              "text": "CanteenM is an American restaurant with a 4.6-star rating and is open 24 hours."
            },
            "groundingChunkIndices": [0]
          },
          // repeated ...
        ],
        "webSearchQueries": [
          "restaurants near me"
        ],
        "googleMapsWidgetContextToken": "widgetcontent/..."
      }
    }
  ]
}

Gemini API จะแสดงข้อมูลต่อไปนี้พร้อมกับgroundingMetadata

  • groundingChunks: อาร์เรย์ของออบเจ็กต์ที่มีแหล่งที่มาของ maps (uri, placeId และ title)
  • groundingSupports: อาร์เรย์ของก้อนข้อมูลเพื่อเชื่อมต่อข้อความคำตอบของโมเดลกับ แหล่งที่มาใน groundingChunks แต่ละก้อนจะลิงก์ช่วงข้อความ (กำหนดโดย startIndex และ endIndex) กับ groundingChunkIndices อย่างน้อย 1 รายการ ซึ่งเป็น กุญแจสำคัญในการสร้างการอ้างอิงในบรรทัด
  • googleMapsWidgetContextToken: โทเค็นข้อความที่ใช้ในการแสดงผล วิดเจ็ตสถานที่ตามบริบท

ดูข้อมูลโค้ดที่แสดงวิธีแสดงผลการอ้างอิงในข้อความได้ที่ตัวอย่าง ในเอกสารการอ้างอิงด้วย Google Search

แสดงวิดเจ็ตตามบริบทของ Google Maps

หากต้องการใช้ googleMapsWidgetContextToken ที่ส่งคืน คุณต้องโหลด Google Maps JavaScript API

กรณีการใช้งาน

การอ้างอิงด้วย Google Maps รองรับกรณีการใช้งานที่หลากหลายซึ่งรับรู้ตำแหน่ง ตัวอย่างต่อไปนี้แสดงให้เห็นว่าพรอมต์และพารามิเตอร์ต่างๆ สามารถใช้ประโยชน์จาก การอ้างอิงกับ Google Maps ได้อย่างไร ข้อมูลในผลลัพธ์ภาคพื้นของ Google Maps อาจ แตกต่างจากสภาพจริง

การจัดการคำถามเกี่ยวกับสถานที่

ถามคำถามโดยละเอียดเกี่ยวกับสถานที่หนึ่งๆ เพื่อรับคำตอบตามรีวิวของผู้ใช้ Google และข้อมูลอื่นๆ ของ Maps

Python

from google import genai
from google.genai import types

client = genai.Client()

prompt = "Is there a cafe near the corner of 1st and Main that has outdoor seating?"

response = client.models.generate_content(
    model='gemini-2.5-flash-lite',
    contents=prompt,
    config=types.GenerateContentConfig(
        # Turn on the Maps tool
        tools=[types.Tool(google_maps=types.GoogleMaps())],

        # Provide the relevant location context (this is in Los Angeles)
        tool_config=types.ToolConfig(retrieval_config=types.RetrievalConfig(
            lat_lng=types.LatLng(
                latitude=34.050481, longitude=-118.248526))),
    ),
)

print("Generated Response:")
print(response.text)

if grounding := response.candidates[0].grounding_metadata:
  if chunks := grounding.grounding_chunks:
    print('-' * 40)
    print("Sources:")
    for chunk in chunks:
      print(f'- [{chunk.maps.title}]({chunk.maps.uri})')
  ```

JavaScript

import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({});

async function run() {
  const prompt = "Is there a cafe near the corner of 1st and Main that has outdoor seating?";

  const response = await ai.models.generateContent({
    model: 'gemini-2.5-flash',
    contents: prompt,
    config: {
      // Turn on the Maps tool
      tools: [{googleMaps: {}}],
      // Provide the relevant location context (this is in Los Angeles)
      toolConfig: {
        retrievalConfig: {
          latLng: {
            latitude: 34.050481,
            longitude: -118.248526
          }
        }
      }
    },
  });

  console.log("Generated Response:");
  console.log(response.text);

  const chunks = response.candidates[0].groundingMetadata?.groundingChunks;
  if (chunks) {
    console.log('-'.repeat(40));
    console.log("Sources:");
    for (const chunk of chunks) {
      if (chunk.maps) {
        console.log(`- [${chunk.maps.title}](${chunk.maps.uri})`);
      }
    }
  }
}

run();

REST

curl -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent' \
  -H 'Content-Type: application/json' \
  -H "x-goog-api-key: ${GEMINI_API_KEY}" \
  -d '{
  "contents": [{
    "role": "user",
    "parts": [{
      "text": "Is there a cafe near the corner of 1st and Main that has outdoor seating?"
    }]
  }],
  "tools": [{"googleMaps": {}}],
  "toolConfig": {
    "retrievalConfig": {
      "latLng": {"latitude": 34.050481, "longitude": -118.248526}
    }
  }
}'

การปรับเปลี่ยนในแบบของคุณตามตำแหน่ง

รับคำแนะนำที่ปรับให้เหมาะกับค่ากำหนดของผู้ใช้และพื้นที่ทางภูมิศาสตร์ที่เฉพาะเจาะจง

Python

from google import genai
from google.genai import types

client = genai.Client()

prompt = "Which family-friendly restaurants near here have the best playground reviews?"

response = client.models.generate_content(
    model='gemini-2.5-flash',
    contents=prompt,
    config=types.GenerateContentConfig(
      tools=[types.Tool(google_maps=types.GoogleMaps())],
      tool_config=types.ToolConfig(retrieval_config=types.RetrievalConfig(
          # Provide the location as context; this is Austin, TX.
          lat_lng=types.LatLng(
              latitude=30.2672, longitude=-97.7431))),
    ),
)

print("Generated Response:")
print(response.text)

if grounding := response.candidates[0].grounding_metadata:
  if chunks := grounding.grounding_chunks:
    print('-' * 40)
    print("Sources:")
    for chunk in chunks:
      print(f'- [{chunk.maps.title}]({chunk.maps.uri})')

JavaScript

import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({});

async function run() {
  const prompt = "Which family-friendly restaurants near here have the best playground reviews?";

  const response = await ai.models.generateContent({
    model: 'gemini-2.5-flash',
    contents: prompt,
    config: {
      tools: [{googleMaps: {}}],
      toolConfig: {
        retrievalConfig: {
          // Provide the location as context; this is Austin, TX.
          latLng: {
            latitude: 30.2672,
            longitude: -97.7431
          }
        }
      }
    },
  });

  console.log("Generated Response:");
  console.log(response.text);

  const chunks = response.candidates[0].groundingMetadata?.groundingChunks;
  if (chunks) {
    console.log('-'.repeat(40));
    console.log("Sources:");
    for (const chunk of chunks) {
      if (chunk.maps) {
        console.log(`- [${chunk.maps.title}](${chunk.maps.uri})`);
      }
    }
  }
}

run();

REST

curl -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent' \
  -H 'Content-Type: application/json' \
  -H "x-goog-api-key: ${GEMINI_API_KEY}" \
  -d '{
  "contents": [{
    "role": "user",
    "parts": [{
      "text": "Which family-friendly restaurants near here have the best playground reviews?"
    }],
  }],
  "tools": [{"googleMaps": {}}],
  "toolConfig": {
    "retrievalConfig": {
      "latLng": {"latitude": 30.2672, "longitude": -97.7431}
    }
  }
}'

ช่วยวางแผนการเดินทาง

สร้างแผนการเดินทางหลายวันพร้อมเส้นทางและข้อมูลเกี่ยวกับสถานที่ต่างๆ ซึ่งเหมาะสำหรับแอปพลิเคชันการเดินทาง

ในตัวอย่างนี้ มีการขอ googleMapsWidgetContextToken โดยการเปิดใช้วิดเจ็ตในเครื่องมือ Google Maps เมื่อเปิดใช้แล้ว คุณจะใช้โทเค็นที่ส่งคืน เพื่อแสดงวิดเจ็ตสถานที่ตามบริบทได้โดยใช้ <gmp-places-contextual> component จาก Google Maps JavaScript API

Python

from google import genai
from google.genai import types

client = genai.Client()

prompt = "Plan a day in San Francisco for me. I want to see the Golden Gate Bridge, visit a museum, and have a nice dinner."

response = client.models.generate_content(
    model='gemini-2.5-flash',
    contents=prompt,
    config=types.GenerateContentConfig(
      tools=[types.Tool(google_maps=types.GoogleMaps(enable_widget=True))],
      tool_config=types.ToolConfig(retrieval_config=types.RetrievalConfig(
          # Provide the location as context, this is in San Francisco.
          lat_lng=types.LatLng(
              latitude=37.78193, longitude=-122.40476))),
    ),
)

print("Generated Response:")
print(response.text)

if grounding := response.candidates[0].grounding_metadata:
  if grounding.grounding_chunks:
    print('-' * 40)
    print("Sources:")
    for chunk in grounding.grounding_chunks:
      print(f'- [{chunk.maps.title}]({chunk.maps.uri})')

  if widget_token := grounding.google_maps_widget_context_token:
    print('-' * 40)
    print(f'<gmp-place-contextual context-token="{widget_token}"></gmp-place-contextual>')

JavaScript

import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({});

async function run() {
  const prompt = "Plan a day in San Francisco for me. I want to see the Golden Gate Bridge, visit a museum, and have a nice dinner.";

  const response = await ai.models.generateContent({
    model: 'gemini-2.5-flash',
    contents: prompt,
    config: {
      tools: [{googleMaps: {enableWidget: true}}],
      toolConfig: {
        retrievalConfig: {
          // Provide the location as context, this is in San Francisco.
          latLng: {
            latitude: 37.78193,
            longitude: -122.40476
          }
        }
      }
    },
  });

  console.log("Generated Response:");
  console.log(response.text);

  const groundingMetadata = response.candidates[0]?.groundingMetadata;
  if (groundingMetadata) {
    if (groundingMetadata.groundingChunks) {
      console.log('-'.repeat(40));
      console.log("Sources:");
      for (const chunk of groundingMetadata.groundingChunks) {
        if (chunk.maps) {
          console.log(`- [${chunk.maps.title}](${chunk.maps.uri})`);
        }
      }
    }

    if (groundingMetadata.googleMapsWidgetContextToken) {
      console.log('-'.repeat(40));
      document.body.insertAdjacentHTML('beforeend', `<gmp-place-contextual context-token="${groundingMetadata.googleMapsWidgetContextToken}`"></gmp-place-contextual>`);
    }
  }
}

run();

REST

curl -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent' \
  -H 'Content-Type: application/json' \
  -H "x-goog-api-key: ${GEMINI_API_KEY}" \
  -d '{
  "contents": [{
    "role": "user",
    "parts": [{
      "text": "Plan a day in San Francisco for me. I want to see the Golden Gate Bridge, visit a museum, and have a nice dinner."
    }]
  }],
  "tools": [{"googleMaps": {"enableWidget":"true"}}],
  "toolConfig": {
    "retrievalConfig": {
    "latLng": {"latitude": 37.78193, "longitude": -122.40476}
  }
  }
}'

เมื่อแสดงผลวิดเจ็ตแล้ว วิดเจ็ตจะมีลักษณะดังนี้

ตัวอย่างวิดเจ็ตแผนที่เมื่อแสดงผล

ข้อกำหนดในการใช้งานบริการ

ส่วนนี้อธิบายข้อกำหนดในการใช้งานบริการสำหรับ Grounding with Google Maps

แจ้งให้ผู้ใช้ทราบเกี่ยวกับการใช้แหล่งข้อมูลของ Google Maps

ผลการค้นหาที่อิงตามข้อเท็จจริงของ Google Maps แต่ละรายการจะมีแหล่งข้อมูลใน groundingChunks ที่สนับสนุนคำตอบแต่ละรายการ นอกจากนี้ ระบบยังแสดงข้อมูลเมตาดังต่อไปนี้ด้วย

  • URI ต้นทาง
  • title
  • รหัส

เมื่อแสดงผลลัพธ์จาก Grounding with Google Maps คุณต้องระบุแหล่งที่มาของ Google Maps ที่เกี่ยวข้อง และแจ้งให้ผู้ใช้ทราบข้อมูลต่อไปนี้

  • แหล่งที่มาของ Google Maps ต้องอยู่ต่อจากเนื้อหาที่สร้างขึ้นซึ่งแหล่งที่มานั้นรองรับทันที เนื้อหาที่สร้างขึ้นนี้เรียกอีกอย่างว่าผลการค้นหาที่อิงตามข้อมูลของ Google Maps
  • แหล่งข้อมูลของ Google Maps ต้องดูได้ภายใน 1 การโต้ตอบของผู้ใช้

สำหรับแหล่งที่มาแต่ละรายการใน groundingChunks และใน grounding_chunks.maps.placeAnswerSources.reviewSnippets ระบบจะต้องสร้างตัวอย่างลิงก์ ตามข้อกำหนดต่อไปนี้

  • ระบุแหล่งที่มาแต่ละแหล่งไปยัง Google Maps ตามข้อความของ Google Maps หลักเกณฑ์การระบุแหล่งที่มา
  • แสดงชื่อแหล่งข้อมูลที่ระบุไว้ในการตอบกลับ
  • ลิงก์ไปยังแหล่งที่มาโดยใช้ uri หรือ googleMapsUri จากคำตอบ

รูปภาพเหล่านี้แสดงข้อกำหนดขั้นต่ำสำหรับการแสดงแหล่งที่มาและลิงก์ Google Maps

พรอมต์พร้อมคำตอบที่แสดงแหล่งที่มา

คุณยุบมุมมองของแหล่งที่มาได้

พรอมต์ที่มีการตอบกลับและแหล่งข้อมูลที่ยุบแล้ว

ไม่บังคับ: ปรับปรุงตัวอย่างลิงก์ด้วยเนื้อหาเพิ่มเติม เช่น

  • ระบบจะแทรกฟาวิคอนของ Google Maps ก่อนข้อความระบุแหล่งที่มาของ Google Maps
  • รูปภาพจาก URL แหล่งที่มา (og:image)

ดูข้อมูลเพิ่มเติมเกี่ยวกับผู้ให้บริการข้อมูล Google Maps บางรายและข้อกำหนดของใบอนุญาตได้ที่ประกาศทางกฎหมายของ Google Maps และ Google Earth

หลักเกณฑ์การระบุแหล่งที่มาของข้อความใน Google Maps

เมื่อระบุแหล่งที่มาของ Google Maps ในข้อความ ให้ทำตามหลักเกณฑ์ต่อไปนี้

  • โปรดอย่าแก้ไขข้อความ Google Maps ในลักษณะใดก็ตาม
    • อย่าเปลี่ยนการใช้อักษรตัวพิมพ์ใหญ่ของ Google Maps
    • อย่าวาง Google Maps ในหลายบรรทัด
    • อย่าแปล Google Maps เป็นภาษาอื่น
    • ป้องกันไม่ให้เบราว์เซอร์แปล Google Maps โดยใช้แอตทริบิวต์ HTML translate="no"
  • จัดรูปแบบข้อความ Google Maps ตามที่อธิบายไว้ในตารางต่อไปนี้
พร็อพเพอร์ตี้ รูปแบบ
Font family Roboto คุณจะโหลดฟอนต์หรือไม่ก็ได้
Fallback font family แบบอักษรเนื้อหาแบบ Sans Serif ที่ใช้ในผลิตภัณฑ์อยู่แล้ว หรือ "Sans-Serif" เพื่อเรียกใช้แบบอักษรเริ่มต้นของระบบ
Font style ปกติ
Font weight 400
Font color สีขาว ดำ (#1F1F1F) หรือเทา (#5E5E5E) รักษาระดับความแตกต่างที่เข้าถึงได้ (4.5:1) กับพื้นหลัง
Font size
  • ขนาดแบบอักษรขั้นต่ำ: 12sp
  • ขนาดแบบอักษรสูงสุด: 16sp
  • ดูข้อมูลเกี่ยวกับ sp ได้ที่หน่วยขนาดแบบอักษรในเว็บไซต์ Material Design
Spacing ปกติ

ตัวอย่าง CSS

CSS ต่อไปนี้จะแสดงผล Google Maps ด้วยรูปแบบการพิมพ์และสีที่เหมาะสมบนพื้นหลังสีขาวหรือสีอ่อน

CSS

@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');

.GMP-attribution {

font-family: Roboto, Sans-Serif;
font-style: normal;
font-weight: 400;
font-size: 1rem;
letter-spacing: normal;
white-space: nowrap;
color: #5e5e5e;
}

โทเค็นบริบท รหัสสถานที่ และรหัสรีวิว

ข้อมูล Google Maps ประกอบด้วยโทเค็นบริบท รหัสสถานที่ และรหัสรีวิว คุณอาจแคช จัดเก็บ และส่งออกข้อมูลการตอบกลับต่อไปนี้

  • googleMapsWidgetContextToken
  • placeId
  • reviewId

ข้อจำกัดในการแคชในข้อกำหนดการห้ามบินด้วย Google Maps จะไม่ มีผล

กิจกรรมและเขตแดนที่ไม่อนุญาต

การอ้างอิงด้วย Google Maps มีข้อจำกัดเพิ่มเติมสำหรับเนื้อหาและ กิจกรรมบางอย่างเพื่อรักษาแพลตฟอร์มให้ปลอดภัยและเชื่อถือได้ นอกเหนือจากข้อจำกัดในการใช้งานในข้อกำหนดแล้ว คุณจะไม่ใช้ Grounding กับ Google Maps สำหรับกิจกรรมที่มีความเสี่ยงสูง ซึ่งรวมถึงบริการช่วยเหลือฉุกเฉิน คุณจะไม่เผยแพร่หรือทำการตลาดแอปพลิเคชันที่ให้บริการ Grounding ด้วย Google Maps ในเขตแดนที่ถูกห้าม เขตแดนที่ไม่อนุญาตในปัจจุบันมีดังนี้

  • จีน
  • ไครเมีย
  • คิวบา
  • สาธารณรัฐประชาชนดอแนตสก์
  • อิหร่าน
  • สาธารณรัฐประชาชนลูฮันสก์
  • เกาหลีเหนือ
  • ซีเรีย
  • เวียดนาม

รายการนี้อาจได้รับการอัปเดตเป็นครั้งคราว

แนวทางปฏิบัติแนะนำ

  • ระบุตำแหน่งของผู้ใช้: เพื่อให้ได้คำตอบที่เกี่ยวข้องและปรับเปลี่ยนในแบบของคุณมากที่สุด ให้ใส่ user_location (ละติจูดและลองจิจูด) ในการกำหนดค่า googleMapsGrounding เสมอเมื่อทราบตำแหน่งของผู้ใช้
  • แสดงวิดเจ็ตตามบริบทของ Google Maps: วิดเจ็ตตามบริบทจะแสดงโดยใช้โทเค็นบริบท googleMapsWidgetContextToken ซึ่งจะแสดงในคำตอบของ Gemini API และใช้เพื่อแสดงเนื้อหาภาพจาก Google Maps ได้ ดูข้อมูลเพิ่มเติมเกี่ยวกับวิดเจ็ตตามบริบทได้ที่ วิดเจ็ตการอ้างอิงด้วย Google Maps ในคู่มือนักพัฒนาซอฟต์แวร์ของ Google
  • แจ้งผู้ใช้ปลายทาง: แจ้งให้ผู้ใช้ปลายทางทราบอย่างชัดเจนว่าระบบกำลังใช้ข้อมูล Google Maps เพื่อตอบคำค้นหาของผู้ใช้ โดยเฉพาะเมื่อเปิดใช้เครื่องมือ
  • ตรวจสอบเวลาในการตอบสนอง: สำหรับแอปพลิเคชันแบบสนทนา ให้ตรวจสอบว่าเวลาในการตอบสนอง P95 สำหรับคำตอบที่อิงตามข้อมูลยังคงอยู่ภายในเกณฑ์ที่ยอมรับได้เพื่อ รักษาประสบการณ์ของผู้ใช้ให้ราบรื่น
  • ปิดเมื่อไม่จำเป็น: การกราวด์ด้วย Google Maps จะปิดอยู่โดยค่าเริ่มต้น เปิดใช้ ("tools": [{"googleMaps": {}}]) เฉพาะเมื่อการค้นหามีบริบททางภูมิศาสตร์ที่ชัดเจน เพื่อเพิ่มประสิทธิภาพและต้นทุน

ข้อจำกัด

  • ขอบเขตทางภูมิศาสตร์: ปัจจุบันการใช้ Grounding กับ Google Maps พร้อมให้บริการทั่วโลก
  • การรองรับโมเดล: เฉพาะโมเดล Gemini บางรุ่นเท่านั้นที่รองรับการอ้างอิงจาก Google Maps ได้ ได้แก่ Gemini 2.5 Flash-Lite, Gemini 2.5 Pro, Gemini 2.5 Flash และ Gemini 2.0 Flash (แต่ไม่รองรับ 2.0 Flash Lite)
  • อินพุต/เอาต์พุตหลายรูปแบบ: ปัจจุบันการอ้างอิงกับ Google Maps ไม่รองรับอินพุตหรือเอาต์พุตหลายรูปแบบนอกเหนือจากข้อความและวิดเจ็ตแผนที่ตามบริบท
  • สถานะเริ่มต้น: เครื่องมือการอ้างอิงด้วย Google Maps จะปิดอยู่โดยค่าเริ่มต้น คุณต้องเปิดใช้ฟีเจอร์นี้อย่างชัดแจ้งในคำขอ API

ราคาและขีดจำกัดอัตรา

ราคาของ Grounding with Google Maps จะอิงตามการค้นหา ปัจจุบันอัตราค่าบริการคือ $25 / 1,000 พรอมต์ที่อิงตามความจริง ระบบจะนับคำขอเป็นส่วนหนึ่งของโควต้าเมื่อพรอมต์แสดงผลลัพธ์ที่อิงตามข้อมูลของ Google Maps อย่างน้อย 1 รายการ (เช่น ผลลัพธ์ที่มีแหล่งที่มาของ Google Maps อย่างน้อย 1 รายการ) หากมีการส่งการค้นหาหลายรายการไปยัง Google Maps จากคำขอเดียว ระบบจะนับเป็นคำขอเดียวตาม ขีดจำกัดอัตราการใช้งาน

ดูข้อมูลการกำหนดราคาโดยละเอียดได้ที่หน้าราคาของ Gemini API

โมเดลที่รองรับ

คุณดูความสามารถของโมเดลได้ในหน้าภาพรวมของโมเดล

รุ่น การเชื่อมต่อแหล่งข้อมูลกับ Google Maps
Gemini 2.5 Pro ✔️
Gemini 2.5 Flash ✔️
Gemini 2.5 Flash-Lite ✔️
Gemini 2.0 Flash ✔️

ขั้นตอนถัดไป