การอ้างอิงข้อมูลด้วย
การอ้างอิงข้อมูลใน
- เพิ่มความถูกต้องของข้อเท็จจริง: ลดอาการหลอนของโมเดลโดยอิงคำตอบจากฐานข้อมูลของ Google ที่มีสถานที่และธุรกิจในชีวิตจริงมากกว่า 250 ล้านแห่ง
- เข้าถึงข้อมูลแบบเรียลไทม์: ตอบคำถามโดยใช้ข้อมูลแบบเรียลไทม์ เช่น เวลาทำการปัจจุบันและสถานะแบบเรียลไทม์ของสถานีชาร์จ EV
- ระบุแหล่งที่มา: สร้างความไว้วางใจของผู้ใช้ด้วยการแสดงแหล่งที่มาของสถานที่
Google Maps แห่งและลิงก์ที่เกี่ยวข้องกับการอ้างอิงตามตำแหน่งของโมเดลโดยตรง
โมเดลที่รองรับ
gemini-4-argongemini-3.8-flash(และgemini-3.7-flash,gemini-3.6-flashและgemini-3.5-flashรุ่นเก่า)gemini-3.5-flash-lite(และgemini-3.1-flash-liteรุ่นเก่า)
โมเดล gemini-3.1-pro-preview และโมเดล Gemini 2.5 สำหรับการใช้งานทั่วไป (ซึ่งเลิกใช้งานแล้ว) ก็รองรับความสามารถนี้เช่นกัน
ภาษาที่สนับสนุน
ดูภาษาที่รองรับสำหรับโมเดล Gemini
อ้างอิงข้อมูลในโมเดลด้วย Google Maps
|
คลิกผู้ให้บริการ Gemini API เพื่อดูเนื้อหาและโค้ดเฉพาะของผู้ให้บริการในหน้านี้ |
เมื่อสร้างอินสแตนซ์ GenerativeModel ให้ระบุ GoogleMaps เป็น tool ที่โมเดลสามารถใช้เพื่อสร้างคำตอบได้
Swift
import CoreLocation
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: [.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.
tools: [ { googleMaps: {} } ],
// 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-US',
),
);
// 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
ดูวิธีเลือกโมเดล ที่เหมาะกับ Use Case และแอปของคุณ
แนวทางปฏิบัติแนะนำและเคล็ดลับในการปรับปรุงผลลัพธ์
ส่วนนี้จะอธิบายแนวทางปฏิบัติแนะนำทั่วไปบางประการสำหรับการใช้การอ้างอิงข้อมูลในโลกความจริงกับ
แนวทางปฏิบัติแนะนำโดยทั่วไป
จัดหาเครื่องมือเมื่อจำเป็นเท่านั้น: เพื่อเพิ่มประสิทธิภาพและลดต้นทุน ให้โมเดลเข้าถึงเครื่องมือการอ้างอิงข้อมูลใน
Google Maps เฉพาะเมื่อ Use Case มีบริบททางภูมิศาสตร์ที่ชัดเจนเท่านั้นระบุตำแหน่งของผู้ใช้: เพื่อให้ได้คำตอบที่เกี่ยวข้องและปรับเปลี่ยนในแบบของคุณมากที่สุด (และเมื่อทราบตำแหน่งของผู้ใช้) ให้ระบุตำแหน่งของผู้ใช้ (โดยใช้ละติจูดและลองจิจูดผ่าน
latLng) ในการกำหนดค่าเครื่องมือการอ้างอิงข้อมูลในGoogle Maps แจ้งให้ผู้ใช้ปลายทางทราบ: แจ้งให้ผู้ใช้ปลายทางทราบอย่างชัดเจนว่ามีการใช้ข้อมูล
Google Maps เพื่อตอบคำถามของผู้ใช้ การให้แหล่งที่มาจากGoogle Maps แก่ผู้ใช้ปลายทางเป็นข้อกำหนดการใช้บริการสำหรับเครื่องมือการอ้างอิงข้อมูลในGoogle Maps
ใช้พร็อพเพอร์ตี้ของสถานที่ในพรอมต์
ส่วนนี้จะแสดงพร็อพเพอร์ตี้ของสถานที่ที่ใช้อธิบายสถานที่ตั้งและใช้โดยการอ้างอิงข้อมูลในโลกความจริงด้วย
ตัวอย่างพร็อพเพอร์ตี้ของสถานที่
รายการนี้แสดงตัวอย่างพร็อพเพอร์ตี้เกี่ยวกับสถานที่ที่โมเดลสามารถใช้เพื่อสร้างคำตอบได้ โดยเรียงตามตัวอักษร
- ที่อยู่
- การรับสินค้าโดยไม่ต้องลงจากรถ
- บัตรเดบิต
- ระยะทาง
- ที่จอดรถแบบไม่เสียค่าใช้จ่าย
- ดนตรีสด
- เมนูสำหรับเด็ก
- เวลาทำการ
- ตัวเลือกการชำระเงิน (เช่น เงินสดหรือบัตรเครดิต)
- คำตอบเกี่ยวกับสถานที่
- เป็นมิตรต่อสัตว์เลี้ยง
- เสิร์ฟเบียร์
- มีบริการอาหารมังสวิรัติ
- รองรับเก้าอี้รถเข็น
- Wifi
คำตอบเกี่ยวกับสถานที่คือคำตอบจากการอ้างอิงข้อมูลใน
ตัวอย่างพรอมต์ที่ใช้พร็อพเพอร์ตี้ของสถานที่
ตัวอย่างต่อไปนี้ใช้พร็อพเพอร์ตี้ของสถานที่ในพรอมต์เกี่ยวกับสถานที่ประเภทต่างๆ การอ้างอิงข้อมูลใน
วางแผนมื้อค่ำกับครอบครัว: พิจารณาว่าร้านอาหารเหมาะสำหรับครอบครัวหรือไม่ และร้านอาหารมีบริการที่สะดวกสบายหรือไม่
- ตัวอย่างพรอมต์: "ร้านอาหารอิตาเลียน" เหมาะสำหรับเด็กไหม และมีบริการซื้อกลับบ้านไหม คะแนนของพวกเขาคือเท่าใด
ตรวจสอบการช่วยเหลือพิเศษให้เพื่อน: ดูว่าสถานที่นั้นๆ ตรงตามความต้องการด้านการช่วยเหลือพิเศษที่เฉพาะเจาะจงหรือไม่
- ตัวอย่างพรอมต์: ฉันต้องการร้านอาหารที่มีทางเข้าที่รองรับเก้าอี้รถเข็น
ค้นหาสถานที่สำหรับมื้อดึก: ค้นหาสถานที่ที่เปิดให้บริการอาหารมื้อใดมื้อหนึ่งในช่วงเวลาที่กำหนด
- ตัวอย่างพรอมต์: ร้าน "Burger Joint" เปิดอยู่ไหม มีอาหารเย็นไหม เวลาทำการของวันศุกร์คือเมื่อไหร่
พบลูกค้าเพื่อดื่มกาแฟ: ประเมินความเหมาะสมของคาเฟ่สำหรับการประชุมทางธุรกิจโดยพิจารณาจากสิ่งอำนวยความสะดวก ข้อเสนอ และตัวเลือกการชำระเงิน
- ตัวอย่างพรอมต์: "Cafe Central" มี Wi-Fi ไหม ที่นี่เสิร์ฟกาแฟไหม มีระดับราคาเท่าใด และรับบัตรเครดิตหรือไม่
โปรดทราบว่าข้อมูลในผลลัพธ์ที่อิงตามข้อมูลจริงของ
วิธีการทำงานของการอ้างอิงข้อมูลใน Google Maps
เมื่อคุณให้เครื่องมือ GoogleMaps แก่โมเดล โมเดลจะจัดการเวิร์กโฟลว์ทั้งหมดของการค้นหา การประมวลผล และการอ้างอิงข้อมูลโดยอัตโนมัติ
เวิร์กโฟลว์ของโมเดลมีดังนี้
รับพรอมต์: แอปของคุณส่งพรอมต์ไปยังโมเดล Gemini โดยเปิดใช้เครื่องมือ
GoogleMapsวิเคราะห์พรอมต์: โมเดลจะวิเคราะห์พรอมต์และพิจารณาว่า
Google Maps สามารถปรับปรุงคำตอบได้หรือไม่ เช่น หากพรอมต์มีบริบททางภูมิศาสตร์ (เช่น "ร้านกาแฟใกล้ฉัน" "พิพิธภัณฑ์ในซานฟรานซิสโก")เรียกใช้เครื่องมือ: โมเดลจะเรียกใช้เครื่องมือการอ้างอิงข้อมูลใน
Google Maps เมื่อรับรู้ถึงเจตนาทางภูมิศาสตร์ส่งคำค้นหาไปยัง
Google Maps : บริการ Grounding withGoogle Maps จะค้นหาข้อมูลที่เกี่ยวข้องจากGoogle Maps (เช่น สถานที่ รีวิว รูปภาพ ที่อยู่ เวลาทำการ)คุณสามารถเลือกที่จะใส่ละติจูดและลองจิจูดในการกำหนดค่าของเครื่องมือ (หรือแม้แต่ในพรอมต์โดยตรง) เพื่อให้ได้ผลลัพธ์ที่เกี่ยวข้องและปรับเปลี่ยนในแบบของคุณมากขึ้น
Google Maps เครื่องมือนี้เป็นเครื่องมือค้นหาข้อความและทำงานคล้ายกับการค้นหาในGoogle Maps โดยคำค้นหาในพื้นที่ ("ใกล้ฉัน") จะใช้พิกัด ในขณะที่คำค้นหาที่เจาะจงหรือไม่ใช่ในพื้นที่ไม่น่าจะได้รับอิทธิพลจากตำแหน่งที่ชัดเจนประมวลผลผลลัพธ์จาก
Google Maps : โมเดลจะประมวลผลผลลัพธ์จากGoogle Maps และกำหนดคำตอบสำหรับพรอมต์เดิมแสดงผลลัพธ์ที่อิงตาม
Google Maps Grounded Result: โมเดลจะแสดงคำตอบสุดท้ายที่ใช้ง่ายซึ่งอิงตามผลลัพธ์ของGoogle Maps คำตอบนี้ประกอบด้วย- คำตอบแบบข้อความของโมเดล
- ออบเจ็กต์
groundingMetadataที่มีผลลัพธ์Google Maps และแหล่งที่มา
โปรดทราบว่าการระบุ groundingMetadata จึงไม่ใช่ผลลัพธ์ที่มีการอ้างอิงของ
ทำความเข้าใจผลลัพธ์ที่อิงตามข้อมูลที่เชื่อถือได้
หากโมเดลอิงคำตอบตามผลการค้นหาของ groundingMetadata ซึ่งมีข้อมูลที่มีโครงสร้างที่จำเป็นสำหรับการยืนยันคำกล่าวอ้างและสร้างประสบการณ์การใช้งานแหล่งข้อมูลที่สมบูรณ์ในแอปพลิเคชันของคุณ
ออบเจ็กต์ groundingMetadata ในผลลัพธ์ที่อิงตามข้อมูลจริงของ
groundingChunks: อาร์เรย์ของออบเจ็กต์ที่มีแหล่งที่มาmaps(uri,placeIdและtitle)groundingSupports: อาร์เรย์ของกลุ่มข้อมูลเพื่อเชื่อมต่อคำตอบของโมเดลtextกับแหล่งข้อมูลในgroundingChunksแต่ละกลุ่มจะลิงก์ข้อความsegment(กำหนดโดยstartIndexและendIndex) กับgroundingChunkIndicesอย่างน้อย 1 รายการ ช่องนี้ช่วยให้คุณสร้างลิงก์แหล่งที่มาในบรรทัดได้ ดูวิธีปฏิบัติตามข้อกำหนดการใช้งานบริการได้ที่ด้านล่างในหน้านี้
ต่อไปนี้คือตัวอย่างการตอบกลับที่มีออบเจ็กต์ 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]
}
]
}
}
]
}
ข้อกำหนดในการใช้บริการ
ส่วนนี้อธิบายข้อกำหนดการใช้บริการสำหรับการอ้างอิงข้อมูลด้วย
แจ้งให้ผู้ใช้ทราบถึงแหล่งที่มา Google Maps แหล่ง
ในผลลัพธ์ที่อิงตามข้อมูลจริงของ groundingChunks ที่สนับสนุนคำตอบแต่ละรายการ ระบบจะแสดงข้อมูลเมตาต่อไปนี้ด้วย
- URI ต้นทาง
- ตำแหน่ง
- รหัส
ในแอปของคุณ เมื่อแสดงผลลัพธ์จากการอ้างอิงข้อมูลใน
แหล่งที่มา
Google Maps รายการต้องอยู่ต่อจากเนื้อหาที่สร้างขึ้นซึ่งแหล่งที่มาสนับสนุนทันที เนื้อหาที่สร้างขึ้นนี้เรียกอีกอย่างว่าผลลัพธ์ที่อิงตามข้อมูลGoogle Maps แหล่งที่มา
Google Maps ต้องดูได้ภายในการโต้ตอบของผู้ใช้ 1 ครั้ง
วิธีรับค่าสำหรับการแสดงแหล่งที่มาจากผลลัพธ์ที่อิงตามข้อมูลจริงของ
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
}
}
}
แสดงแหล่งข้อมูล Google Maps รายการพร้อมลิงก์ Google Maps รายการ
สำหรับแหล่งที่มาแต่ละแหล่งใน groundingChunks
ต้องสร้างตัวอย่างลิงก์ตามข้อกำหนดต่อไปนี้
- ระบุแหล่งที่มาแต่ละแหล่งให้กับ
Google Maps ตามหลักเกณฑ์การระบุแหล่งที่มาของข้อความของGoogle Maps - แสดงชื่อแหล่งที่มาที่ระบุไว้ในคำตอบ
- ลิงก์ไปยังแหล่งที่มาโดยใช้
uriจากการตอบกลับ
คุณสามารถยุบมุมมองแหล่งข้อมูลได้
คุณสามารถปรับปรุงตัวอย่างลิงก์ด้วยเนื้อหาเพิ่มเติมได้ (ไม่บังคับ) เช่น
- ไอคอน Fav ของ
Google Maps ที่แทรกไว้ก่อนการระบุแหล่งที่มาของข้อความGoogle Maps - รูปภาพจาก URL แหล่งที่มา (
og:image)
ดูข้อมูลเพิ่มเติมเกี่ยวกับผู้ให้บริการข้อมูล
หลักเกณฑ์การระบุแหล่งที่มาของข้อความ Google Maps รายการ
เมื่อระบุแหล่งที่มาของ
อย่าแก้ไขข้อความ
Google Mapsไม่ว่าในลักษณะใดก็ตาม- อย่าเปลี่ยนการใช้อักษรตัวพิมพ์ใหญ่ของข้อความ
Google Maps - อย่าตัดข้อความ
Google Mapsขึ้นบรรทัดใหม่หลายบรรทัด - อย่าแปลข้อความ
Google Mapsเป็นภาษาอื่น - ป้องกันไม่ให้เบราว์เซอร์แปลข้อความ
Google Mapsโดยใช้แอตทริบิวต์ HTMLtranslate="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;
}
การแคชรหัสสถานที่
placeId
ข้อจำกัดเกี่ยวกับการแคชในข้อกำหนดการเชื่อมต่อแหล่งข้อมูลกับ Google Maps จะไม่มีผลกับข้อมูลนี้
กิจกรรมและเขตแดนที่ไม่อนุญาต
การอ้างอิงข้อมูลใน
คุณจะไม่ใช้การเชื่อมต่อแหล่งข้อมูลด้วย
Google Maps สำหรับกิจกรรมที่มีความเสี่ยงสูง รวมถึงบริการหน่วยกู้ภัยฉุกเฉินคุณจะไม่จัดจำหน่ายหรือทำการตลาดแอปพลิเคชันที่นำเสนอการอ้างอิงข้อมูลด้วย
Google Maps ในเขตแดนที่ไม่อนุญาต ดูข้อมูลเพิ่มเติมได้ที่เขตแดนที่ไม่อนุญาตให้ใช้ Google Maps Platform รายการเขตแดนที่ไม่อนุญาตอาจมีการอัปเดตเป็นครั้งคราว
ผลลัพธ์ที่อิงตามข้อมูลและการตรวจสอบ AI ในคอนโซล Firebase
หากคุณเปิดใช้การตรวจสอบ AI ในคอนโซล Firebase ระบบจะจัดเก็บคำตอบไว้ใน Cloud Logging โดยค่าเริ่มต้น ข้อมูลนี้จะมีระยะเวลาเก็บรักษา 30 วัน
คุณมีหน้าที่รับผิดชอบในการตรวจสอบว่าระยะเวลาเก็บรักษานี้หรือระยะเวลาที่กำหนดเองที่คุณตั้งค่าไว้สอดคล้องกับกรณีการใช้งานที่เฉพาะเจาะจงของคุณและข้อกำหนดด้านการปฏิบัติตามข้อกำหนดเพิ่มเติมสำหรับผู้ให้บริการ Gemini API ที่คุณเลือกอย่างเต็มที่ ซึ่งได้แก่ Gemini Developer API หรือ Agent Platform Gemini API (formerly Vertex AI) (ดูส่วนข้อกำหนดในการให้บริการภายในข้อกำหนดเฉพาะบริการ) คุณอาจต้องปรับระยะเวลาเก็บรักษาใน Cloud Logging เพื่อให้เป็นไปตามข้อกำหนดเหล่านี้
ราคาและการจำกัดอัตราคำขอ
ราคาของการอ้างอิงข้อมูลใน
อย่าลืมตรวจสอบรายละเอียดเกี่ยวกับราคา ความพร้อมใช้งานของโมเดล และขีดจำกัดสำหรับการอ้างอิงข้อมูลด้วย