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

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

การเชื่อมโยงกับ Google Maps มีข้อดีดังนี้

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

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

  • gemini-3.1-pro-preview
  • gemini-3.5-flash
  • 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    • ตัวอย่างพรอมต์: ร้าน "Cafe Central" มี Wifi ไหม ร้านนี้เสิร์ฟกาแฟไหม_ ระดับราคาของร้านเป็นอย่างไร และร้านรับบัตรเครดิตไหม

โปรดทราบว่าข้อมูลใน 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
    • (Web 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: อาร์เรย์ของ Chunk เพื่อเชื่อมต่อ text คำตอบของโมเดลกับแหล่งที่มาใน groundingChunks Chunk แต่ละรายการจะลิงก์ segment ข้อความ (กำหนดโดย startIndex และ endIndex) กับ groundingChunkIndices อย่างน้อย 1 รายการ ฟิลด์นี้ช่วยให้คุณสร้างลิงก์แหล่งที่มาแบบอินไลน์ได้ ดูวิธีปฏิบัติตามข้อกำหนดในการใช้งานบริการในหน้านี้
  • (Web 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

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

  • URI ต้นทาง
  • ชื่อ
  • รหัส

เมื่อแสดงผลการค้นหาจากการเชื่อมโยงกับ 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 คุณต้องสร้างตัวอย่างลิงก์ตามข้อกำหนดต่อไปนี้

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

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

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

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

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

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

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

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

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

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

  • คุณจะไม่เผยแพร่หรือทำการตลาดแอปพลิเคชันที่ให้บริการการเชื่อมโยง กับ 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 Grounded Result อย่างน้อย 1 รายการสำเร็จ (หมายความว่าคำตอบมีแหล่งที่มาจาก Google Maps อย่างน้อย 1 รายการ) หากมีการส่งคำค้นหาหลายรายการไปยัง Google Mapsจากคำขอเดียว ระบบจะนับเป็นคำขอเดียวตาม ขีดจำกัดอัตรา

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