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

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

การเชื่อมต่อแหล่งข้อมูลด้วย Google Maps มีประโยชน์ดังนี้

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

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

  • gemini-3.1-pro-preview
  • gemini-3-flash-preview
  • gemini-3.1-flash-lite
  • gemini-2.5-pro
  • gemini-2.5-flash
  • gemini-2.5-flash-lite

ภาษาที่สนับสนุน

ดูภาษาที่รองรับ สำหรับโมเดล Gemini

อ้างอิงโมเดลด้วย Google Maps

คลิกผู้ให้บริการ Gemini API เพื่อดูเนื้อหาและโค้ดของผู้ให้บริการรายนั้นๆ ในหน้านี้

เมื่อสร้างอินสแตนซ์ GenerativeModel ให้ระบุ GoogleMaps เป็น tool ที่โมเดลใช้สร้างคำตอบได้

Swift


import FirebaseAILogic

// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Example: Coordinates for New York City
let latAndLong = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060)

// (Optional) Define a RetrievalConfig to configure the Grounding with Google Maps tool.
// You can optionally provide a location's coordinates and/or a language code
// for more relevant and personalized Google Maps results.
let retrievalConfig = RetrievalConfig(
    location: latAndLong,
    // Example: Language code for English (US)
    languageCode: "en_US"
)

// Wrap the RetrievalConfig inside a ToolConfig.
let toolConfig = ToolConfig(retrievalConfig: retrievalConfig)

// Create a `GenerativeModel` instance with a model that supports your use case.
let model = ai.generativeModel(
    modelName: "GEMINI_MODEL_NAME",
    // Provide Google Maps as a tool that the model can use to generate its response.
    tools: [Tool.googleMaps()],
    // Add the configuration for the Grounding with Google Maps tool
    // (if this optional config was defined above).
    toolConfig: toolConfig
)

let response = try await model.generateContent("restaurants near me?")
print(response.text ?? "No text in response.")

// Make sure to comply with the "Grounding with Google Maps" usage requirements,
// which includes how you meet service usage requirements

Kotlin


// (Optional) Define a RetrievalConfig to configure the Grounding with Google Maps tool.
// You can optionally provide a location's coordinates and/or a language code
// for more relevant and personalized Google Maps results.
val retrievalConfig = RetrievalConfig(
    // Example: Coordinates for New York City
    latLng = LatLng(latitude = 40.7128, longitude = -74.0060),
    // Example: Language code for English (US)
    languageCode = "en_US"
)

// Wrap the RetrievalConfig inside a ToolConfig.
val toolConfig = ToolConfig(
    retrievalConfig = retrievalConfig
)

// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
    modelName = "GEMINI_MODEL_NAME",
    // Add the configuration for the Grounding with Google Maps tool
    // (if this optional config was defined above).
    toolConfig = toolConfig,
    // Provide Google Maps as a tool that the model can use to generate its response.
    tools = listOf(Tool.googleMaps())
)

val response = model.generateContent("restaurants near me?")
print(response.text)

// Make sure to comply with the "Grounding with Google Maps" usage requirements,
// which includes how you meet service usage requirements

Java


// (Optional) Define a ToolConfig to configure the Grounding with Google Maps tool.
// You can optionally provide a location's coordinates and/or a language code
// for more relevant and personalized Google Maps results.
ToolConfig toolConfig = new ToolConfig(
    null,
    new RetrievalConfig(
        // Example: Coordinates for New York City
        new LatLng(40.7128, -74.0060),
        // Example: Language code for English (US)
       "en_US"
    )
);

// Initialize the Gemini Developer API backend service.
// Create a `GenerativeModel` instance with a model that supports your use case.
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
                .generativeModel("GEMINI_MODEL_NAME",
                        null,
                        null,
                        // Provide Google Maps as a tool that the model can use to generate its response.
                        List.of(Tool.googleMaps()),
                        // Add the configuration for the Grounding with Google Maps tool
                        // (if this optional config was defined above).
                        toolConfig);

// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs.
GenerativeModelFutures model = GenerativeModelFutures.from(ai);

ListenableFuture response = model.generateContent("restaurants near me?");
  Futures.addCallback(response, new FutureCallback() {
      @Override
      public void onSuccess(GenerateContentResponse result) {
          String resultText = result.getText();
          System.out.println(resultText);
      }

      @Override
      public void onFailure(Throwable t) {
          t.printStackTrace();
      }
  }, executor);

// Make sure to comply with the "Grounding with Google Maps" usage requirements,
// which includes how you meet service usage requirements

Web


import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";

// TODO(developer) Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
  // ...
};

// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);

// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// (Optional) Define a toolConfig to configure the Grounding with Google Maps tool.
// You can optionally provide a location's coordinates and/or a language code
// for more relevant and personalized Google Maps results.
const toolConfig = {
  retrievalConfig: {
    // Example: Coordinates for New York City
    latLng: {
      latitude: 40.7128,
      longitude: -74.0060
    },
    // Example: Language code for English (US)
    languageCode: 'en-US'
  }
};

// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(
  ai,
  {
    model: "GEMINI_MODEL_NAME",
    // Provide Google Maps as a tool that the model can use to generate its response.
    // (Optional) Set `enableWidget` to control whether the response contains a `googleMapsWidgetContextToken`.
    tools: [ { googleMaps: { enableWidget: true } } ],
    // Add the configuration for the Grounding with Google Maps tool
    // (if this optional config was defined above).
    toolConfig
  }
);

const result = await model.generateContent("restaurants near me?");

console.log(result.response.text());

// Make sure to comply with the "Grounding with Google Maps" usage requirements,
// which includes how you meet service usage requirements

Dart


import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'firebase_options.dart';

// Initialize FirebaseApp.
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

// (Optional) Define a ToolConfig to configure the Grounding with Google Maps tool.
// You can optionally provide a location's coordinates and/or a language code
// for more relevant and personalized Google Maps results.
final toolConfig = ToolConfig(
  retrievalConfig: RetrievalConfig(
    // Example: Coordinates for New York City
    latLng: LatLng(latitude: 40.712728, longitude: -74.006015),
    // Example: Language code for English (US)
    languageCode: 'en',
  ),
);

// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case.
final model = FirebaseAI.googleAI().generativeModel(
  model: 'GEMINI_MODEL_NAME',
  // Provide Google Maps as a tool that the model can use to generate its response.
  tools: [
    Tool.googleMaps(),
  ],
  // Add the configuration for the Grounding with Google Maps tool
  // (if this optional config was defined above).
  toolConfig: toolConfig,
);

final response = await model.generateContent([Content.text("restaurants near me?")]);
print(response.text);

// Make sure to comply with the "Grounding with Google Maps" usage requirements,
// which includes how you meet service usage requirements

Unity


using Firebase;
using Firebase.AI;

// Initialize the Gemini Developer API backend service
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());

// Example: Coordinates for New York City
var latLng = new LatLng(40.7128, -74.0060);

// (Optional) Define a RetrievalConfig to configure the Grounding with Google Maps tool.
// You can optionally provide a location's coordinates and/or a language code
// for more relevant and personalized Google Maps results.
var retrievalConfig = new RetrievalConfig(latLng, languageCode: "en");

// Wrap the RetrievalConfig inside a ToolConfig.
var toolConfig = new ToolConfig(retrievalConfig: retrievalConfig);

// Create a `GenerativeModel` instance with a model that supports your use case
var model = ai.GetGenerativeModel(
  modelName: "GEMINI_MODEL_NAME",
  // Provide Google Maps as a tool that the model can use to generate its response.
  tools: new[] { new Tool(new GoogleMaps()) },
  // Add the configuration for the Grounding with Google Maps tool
  // (if this optional config was defined above).
  toolConfig: toolConfig
);

var response = await model.GenerateContentAsync("restaurants near me?");
UnityEngine.Debug.Log(response.Text ?? "No text in response.");

// Make sure to comply with the "Grounding with Google Maps" usage requirements,
// which includes how you meet service usage requirements

ดูวิธีเลือกโมเดล (ไม่บังคับ) ที่เหมาะสมกับกรณีการใช้งานและแอปของคุณ

หากต้องการผลลัพธ์ที่เหมาะสม ให้ใช้อุณหภูมิ 1.0 (ซึ่งเป็นค่าเริ่มต้นสำหรับโมเดล Gemini 2.5 และรุ่นต่อๆ ไปทั้งหมด) ดูวิธีตั้งค่าอุณหภูมิในการกำหนดค่าของโมเดล

แนวทางปฏิบัติแนะนำและเคล็ดลับในการปรับปรุงผลลัพธ์

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

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

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

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

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

  • (SDK เว็บเท่านั้น) แสดงผลGoogle Mapsวิดเจ็ตตามบริบท: ระบบจะแสดงผลวิดเจ็ตตามบริบทโดยใช้โทเค็นบริบท googleMapsWidgetContextToken ซึ่งแสดงผลในGemini API การตอบกลับ และสามารถใช้เพื่อแสดงผลเนื้อหาภาพจาก Google Maps ดูข้อมูลเพิ่มเติมเกี่ยวกับวิดเจ็ตตามบริบทได้ที่การอ้างอิงด้วยวิดเจ็ต Google Maps ในเอกสารประกอบของ Google Maps

ใช้พร็อพเพอร์ตี้สถานที่ในพรอมต์

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

ตัวอย่างพร็อพเพอร์ตี้ของสถานที่

รายการนี้แสดงตัวอย่างพร็อพเพอร์ตี้เกี่ยวกับสถานที่ต่างๆ ที่โมเดลของคุณใช้สร้างคำตอบได้ โดยเรียงตามตัวอักษร

  • ที่อยู่
  • การรับสินค้าโดยไม่ต้องลงจากรถ
  • บัตรเดบิต
  • ระยะทาง
  • ที่จอดรถแบบไม่เสียค่าใช้จ่าย
  • ดนตรีสด
  • เมนูสำหรับเด็ก
  • เวลาทำการ
  • ตัวเลือกการชำระเงิน (เช่น เงินสดหรือบัตรเครดิต)
  • คำตอบเกี่ยวกับสถานที่
  • นำสัตว์เลี้ยงเข้าพักได้
  • เสิร์ฟเบียร์
  • มีบริการอาหารมังสวิรัติ
  • รองรับเก้าอี้รถเข็น
  • Wifi

คำตอบเกี่ยวกับสถานที่คือคำตอบจาก Grounding with Google Maps โดยอิงตาม ข้อมูลที่ได้จากรีวิวของผู้ใช้

ตัวอย่างพรอมต์ที่ใช้พร็อพเพอร์ตี้สถานที่

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

  • วางแผนมื้อค่ำกับครอบครัว: ดูว่าร้านอาหารเหมาะสำหรับครอบครัวหรือไม่และมีบริการที่สะดวกหรือไม่

    • ตัวอย่างพรอมต์: "The Italian Place" เหมาะสำหรับเด็กไหม และมีบริการซื้อกลับบ้านไหม วิดีโอเหล่านั้นได้รับการจัดประเภทอย่างไร
  • ตรวจสอบการเข้าถึงสำหรับเพื่อน: ดูว่าสถานที่นั้นตรงกับ ความต้องการด้านการเข้าถึงที่เฉพาะเจาะจงหรือไม่

    • ตัวอย่างพรอมต์: ฉันอยากได้ร้านอาหารที่มีทางเข้าสำหรับเก้าอี้รถเข็น
  • ค้นหาสถานที่สำหรับทานของว่างยามดึก: ค้นหาสถานประกอบการที่เปิดให้บริการ ซึ่งเสิร์ฟอาหารมื้อหนึ่งๆ ในช่วงเวลาที่เฉพาะเจาะจง

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

    • ตัวอย่างพรอมต์: "Cafe Central" มี Wi-Fi ไหม ที่นี่เสิร์ฟกาแฟไหม ร้านค้ามีระดับราคาเท่าใด และรับบัตรเครดิตหรือไม่

โปรดทราบว่าข้อมูลในGoogle Mapsผลลัพธ์ที่อิงตามข้อมูลพื้นฐานอาจแตกต่างจากสภาพถนนจริง

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

เมื่อคุณระบุเครื่องมือ GoogleMaps ให้กับโมเดล โมเดลจะจัดการ เวิร์กโฟลว์ทั้งหมดของการค้นหา ประมวลผล และอ้างอิงข้อมูลโดยอัตโนมัติ

ขั้นตอนการทำงานของโมเดลมีดังนี้

  1. รับพรอมต์: แอปของคุณจะส่งพรอมต์ไปยังโมเดล Gemini โดยเปิดใช้เครื่องมือ GoogleMaps

  2. วิเคราะห์พรอมต์: โมเดลจะวิเคราะห์พรอมต์และพิจารณาว่า Google Maps สามารถปรับปรุงคำตอบได้หรือไม่ เช่น หากพรอมต์ มีบริบททางภูมิศาสตร์ (เช่น "ร้านกาแฟใกล้ฉัน" "พิพิธภัณฑ์ใน เชียงใหม่")

  3. เรียกใช้เครื่องมือ: โมเดลจะจดจำเจตนาทางภูมิศาสตร์ และเรียกใช้เครื่องมือการอ้างอิงกับ Google Maps

  4. ส่งคำค้นหาไปยัง Google Maps: การกราวด์ด้วยGoogle Maps คำค้นหาของบริการ Google Maps เพื่อหาข้อมูลที่เกี่ยวข้อง (เช่น สถานที่ รีวิว รูปภาพ ที่อยู่ เวลาทำการ)

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

  5. ประมวลผลGoogle Mapsผลลัพธ์: โมเดลจะประมวลผลGoogle Mapsผลลัพธ์และสร้างคำตอบสำหรับพรอมต์เดิม

  6. แสดงGoogle Mapsผลลัพธ์ที่อิงตามข้อมูล: โมเดลจะแสดงคำตอบสุดท้ายที่ใช้งานง่ายซึ่งอิงตามGoogle Mapsผลลัพธ์ คำตอบนี้ประกอบด้วย

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

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

ทำความเข้าใจผลลัพธ์ที่อิงตามข้อมูล

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

ออบเจ็กต์ groundingMetadata ในGoogle Maps ผลการค้นหาที่จำกัดมีข้อมูลต่อไปนี้

  • groundingChunks: อาร์เรย์ของออบเจ็กต์ที่มีแหล่งที่มาของ maps (uri, placeId และ title)
  • groundingSupports: อาร์เรย์ของก้อนข้อมูลเพื่อเชื่อมต่อคำตอบของโมเดล text กับแหล่งที่มาใน groundingChunks แต่ละก้อนจะลิงก์ข้อความ segment (กำหนดโดย startIndex และ endIndex) กับ groundingChunkIndices อย่างน้อย 1 รายการ ฟิลด์นี้ช่วยคุณสร้างลิงก์แหล่งที่มาในบรรทัด ดูวิธี ปฏิบัติตามข้อกำหนดการใช้งานบริการ ได้ในหน้านี้
  • (SDK เว็บเท่านั้น) googleMapsWidgetContextToken: โทเค็นข้อความที่ใช้แสดงวิดเจ็ตสถานที่ตามบริบทได้ ระบบจะแสดงฟิลด์นี้เมื่อใช้ Web SDK และหากคุณตั้งค่าพารามิเตอร์ enableWidget เป็น true เท่านั้น

นี่คือตัวอย่างการตอบกลับที่มีออบเจ็กต์ groundingMetadata

{
  "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"
            }
          }
        ],
        "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]
          }
        ],
        "googleMapsWidgetContextToken": "widgetcontent/..."
      }
    }
  ]
}

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

ส่วนนี้อธิบายข้อกำหนดในการใช้บริการสำหรับการอ้างอิงด้วย Google Maps สำหรับผู้ให้บริการ Gemini API ที่คุณเลือก Gemini Developer API หรือ Vertex AI Gemini API (ดูส่วนข้อกำหนดในการให้บริการ ภายในข้อกำหนดเฉพาะของบริการ)

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

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

  • URI ต้นทาง
  • ตำแหน่ง
  • รหัส

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

  • แหล่งที่มาของ Google Maps ต้องอยู่ต่อจากเนื้อหาที่สร้างขึ้น ซึ่งแหล่งที่มานั้นๆ รองรับ เนื้อหาที่สร้างขึ้นนี้เรียกอีกอย่างว่าGoogle Mapsผลลัพธ์ที่อิงตามข้อมูล

  • แหล่งที่มาของ Google Maps ต้องดูได้ภายใน 1 การโต้ตอบของผู้ใช้

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

Swift

// ...

// Get the model's response
let text = response.text

// Get the grounding metadata
if let candidate = response.candidates.first,
   let groundingMetadata = candidate.groundingMetadata {

  // Get sources
  let groundingChunks = groundingMetadata.groundingChunks
  for chunk in groundingChunks {
    if let maps = chunk.maps {
      let title = maps.title  // for example, "Heaven on 7th Marketplace"
      let url = maps.url  // for example, "https://maps.google.com/?cid=13100894621228039586"
      let placeId = maps.placeId  // for example, "places/ChIJ0-zA1vBZwokRon0fGj-6z7U"
      // TODO(developer): show source in the UI
    }
  }
}

Kotlin

// ...

// Get the model's response
val text = response.text

// Get the grounding metadata
val groundingMetadata = response.candidates.firstOrNull()?.groundingMetadata

// Get sources
val groundingChunks = groundingMetadata?.groundingChunks
groundingChunks?.let { chunks ->
  for (chunk in chunks) {
    val title = chunk.maps?.title  // for example, "Heaven on 7th Marketplace"
    val uri = chunk.maps?.uri  // for example, "https://maps.google.com/?cid=13100894621228039586"
    val placeId = chunk.maps?.placeId  // for example, "places/ChIJ0-zA1vBZwokRon0fGj-6z7U"
    // TODO(developer): show source in the UI
  }
}

Java

// ...

Futures.addCallback(response, new FutureCallback() {
  @Override
  public void onSuccess(GenerateContentResponse result) {
    // Get the model's response
    String text = result.getText();

    // Get the grounding metadata
    GroundingMetadata groundingMetadata =
        result.getCandidates()[0].getGroundingMetadata();

    if (groundingMetadata != null) {
      // Get sources
      List chunks = groundingMetadata.getGroundingChunks();
      if (chunks != null) {
        for(GroundingChunk chunk : chunks) {
          GoogleMapsGroundingChunk maps = chunk.getMaps();
          if (maps != null) {
            String title = maps.getTitle();  // for example, "Heaven on 7th Marketplace"
            String uri = maps.getUri();  // for example, "https://maps.google.com/?cid=13100894621228039586"
            String placeId = maps.getPlaceId();  // for example, "places/ChIJ0-zA1vBZwokRon0fGj-6z7U"
            // TODO(developer): show sources in the UI
          }
        }
      }
    }
  }

  @Override
  public void onFailure(Throwable t) {
    t.printStackTrace();
  }
}, executor);

Web

// ...

// Get the model's text response
const text = result.response.text();

// Get the grounding metadata
const groundingMetadata = result.response.candidates?.[0]?.groundingMetadata;

// Get sources
const groundingChunks = groundingMetadata?.groundingChunks;
if (groundingChunks) {
  for (const chunk of groundingChunks) {
    const title = chunk.maps?.title;  // for example, "Heaven on 7th Marketplace"
    const uri = chunk.maps?.uri;  // for example, "https://maps.google.com/?cid=13100894621228039586"
    const placeId = chunk.maps?.placeId;  // for example, "places/ChIJ0-zA1vBZwokRon0fGj-6z7U"
    // TODO(developer): show sources in the UI
  }
}

Dart

// ...

// Get the model's response
final text = response.text;

// Get the grounding metadata
final groundingMetadata = response.candidates.first.groundingMetadata;

// Get sources
final groundingChunks = groundingMetadata?.groundingChunks;
if (groundingChunks != null) {
  for (var chunk in groundingChunks) {
    final title = chunk.maps?.title;  // for example, "Heaven on 7th Marketplace"
    final uri = chunk.maps?.uri;  // for example, "https://maps.google.com/?cid=13100894621228039586"
    final placeId = chunk.maps?.placeId;  // for example, "places/ChIJ0-zA1vBZwokRon0fGj-6z7U"
    // TODO(developer): show sources in the UI
  }
}

Unity

// ...

// Get the model's response
var text = response.Text;

// Get the grounding metadata
var groundingMetadata = response.Candidates.First().GroundingMetadata;

// Get sources
if (groundingMetadata != null) {
  foreach(GroundingChunk chunk in groundingMetadata?.GroundingChunks) {
    if (chunk.Maps != null) {
      var title = chunk.Maps?.Title;  // for example, "Heaven on 7th Marketplace"
      var uri = chunk.Maps?.Uri;  // for example, "https://maps.google.com/?cid=13100894621228039586"
      var placeId = chunk.Maps?.PlaceId;  // for example, "places/ChIJ0-zA1vBZwokRon0fGj-6z7U"
      // TODO(developer): show sources in the UI
    }
  }
}

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

พรอมต์ที่มีการตอบกลับซึ่งแสดงแหล่งที่มา

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

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

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

  • A Google Maps ไอคอน Fav แทรกก่อน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 ตามที่อธิบายไว้ในตารางต่อไปนี้

    พร็อพเพอร์ตี้ รูปแบบ
    ชุดแบบอักษร Roboto คุณจะโหลดฟอนต์หรือไม่ก็ได้
    ชุดแบบอักษรสำรอง แบบอักษรเนื้อหาแบบ Sans Serif ที่ใช้ในผลิตภัณฑ์อยู่แล้ว หรือ "Sans-Serif" เพื่อเรียกใช้แบบอักษรเริ่มต้นของระบบ
    รูปแบบตัวอักษร ปกติ
    น้ำหนักแบบอักษร 400
    สีแบบอักษร สีขาว สีดำ (#1F1F1F) หรือสีเทา (#5E5E5E) รักษาระดับความแตกต่างที่เข้าถึงได้ (4.5:1) กับพื้นหลัง
    ขนาดตัวอักษร ขนาดแบบอักษรขั้นต่ำ: 12sp
    ขนาดแบบอักษรสูงสุด: 16sp
    ดูข้อมูลเกี่ยวกับ sp ได้ที่หน่วยขนาดแบบอักษรใน เว็บไซต์ Material Design
    ระยะห่าง ปกติ

ตัวอย่าง CSS

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

@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ผลการค้นหาที่อิงตามข้อมูลพื้นฐานอาจมีโทเค็นบริบทและรหัสสถานที่ คุณอาจแคช จัดเก็บ และส่งออกข้อมูลการตอบกลับต่อไปนี้

  • (Web SDK เท่านั้น) googleMapsWidgetContextToken
  • placeId

ข้อจำกัดในการแคชในข้อกำหนดการเชื่อมต่อแหล่งข้อมูลกับ Google Maps ไม่มีผลกับข้อมูลนี้

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

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

  • คุณจะไม่ใช้ Grounding กับ Google Maps สำหรับกิจกรรมที่มีความเสี่ยงสูง รวมถึงบริการช่วยเหลือฉุกเฉิน

  • คุณจะไม่จัดจำหน่ายหรือทำการตลาดแอปพลิเคชันที่เสนอ Grounding ด้วย Google Maps ในเขตแดนที่ถูกห้าม ดูข้อมูลเพิ่มเติมได้ที่เขตแดนที่ Google Maps Platform ไม่อนุญาต รายชื่อเขตแดนที่ไม่อนุญาตอาจมีการอัปเดตเป็นครั้งคราว

ผลการค้นหาที่อิงตามข้อมูลจริงและการตรวจสอบ AI ในFirebaseคอนโซล

หากเปิดใช้ การตรวจสอบ AI ในFirebaseคอนโซล ระบบจะจัดเก็บคำตอบไว้ใน Cloud Logging โดยค่าเริ่มต้น ข้อมูลนี้มีระยะเวลาเก็บรักษา 30 วัน

คุณมีหน้าที่รับผิดชอบในการตรวจสอบว่าระยะเวลาเก็บรักษานี้หรือระยะเวลาที่กำหนดเองใดๆ ที่คุณตั้งค่าไว้สอดคล้องกับกรณีการใช้งานเฉพาะของคุณและข้อกำหนดด้านการปฏิบัติตามข้อกำหนดเพิ่มเติมสำหรับGemini APIผู้ให้บริการที่คุณเลือกอย่างครบถ้วน Gemini Developer API หรือ Vertex AI Gemini API (ดูส่วนข้อกำหนดในการให้บริการ ภายในข้อกำหนดเฉพาะของบริการ) คุณอาจต้องปรับระยะเวลาเก็บรักษาใน Cloud Logging เพื่อให้เป็นไปตามข้อกำหนดเหล่านี้

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

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

โปรดอ่านรายละเอียดเกี่ยวกับราคา ความพร้อมใช้งานของโมเดล และขีดจำกัดสำหรับการอ้างอิงจาก Google Maps ในเอกสารประกอบของผู้ให้บริการ Gemini API ที่คุณเลือก Gemini Developer API | Vertex AI Gemini API