การเชื่อมโยงกับ
การเชื่อมโยงกับ
- เพิ่มความถูกต้องตามข้อเท็จจริง: ลดการหลอนของโมเดลโดยอิง คำตอบจากฐานข้อมูลของ Google ที่มีสถานที่และธุรกิจจริงกว่า 250 ล้านแห่ง
- เข้าถึงข้อมูลแบบเรียลไทม์: ตอบคำถามโดยใช้ข้อมูลแบบเรียลไทม์ เช่น เวลาทำการปัจจุบันและสถานะแบบเรียลไทม์ของสถานีชาร์จรถยนต์ไฟฟ้า
- ระบุบริบทที่เป็นภาพ: สร้างความไว้วางใจจากผู้ใช้ด้วยการผสานรวมวิดเจ็ตแผนที่แบบอินเทอร์แอกทีฟ รูปภาพ และ Street View ไว้ข้างๆ การอ้างสิทธิ์ตามสถานที่ตั้งของโมเดล โดยตรง
โมเดลที่รองรับ
gemini-3.1-pro-previewgemini-3.5-flashgemini-3.1-flash-litegemini-2.5-progemini-2.5-flashgemini-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 แก่โมเดลเฉพาะ เมื่อกรณีการใช้งานมีบริบททางภูมิศาสตร์ที่ชัดเจนระบุตำแหน่งของผู้ใช้: หากต้องการให้ได้คำตอบที่เกี่ยวข้องและปรับเปลี่ยนในแบบของคุณมากที่สุด (และเมื่อทราบตำแหน่งของผู้ใช้) ให้ระบุตำแหน่งของผู้ใช้ (โดยใช้ ละติจูดและลองจิจูดผ่าน
latLng) ในการกำหนดค่าเครื่องมือการเชื่อมโยงกับGoogle Maps แจ้งให้ผู้ใช้ปลายทางทราบ: แจ้งให้ผู้ใช้ปลายทางทราบอย่างชัดเจนว่ามีการใช้ข้อมูล
Google Maps เพื่อตอบคำค้นหาของผู้ใช้ การระบุแหล่งที่มาจากGoogle Maps ให้ผู้ใช้ปลายทางทราบเป็นข้อกำหนดในการใช้งานบริการสำหรับเครื่องมือการเชื่อมโยงกับGoogle Maps (Web SDK เท่านั้น) แสดงวิดเจ็ตตามบริบท
Google Maps : ระบบจะแสดงวิดเจ็ตตามบริบทโดยใช้โทเค็นบริบทgoogleMapsWidgetContextTokenซึ่งแสดงในGemini API คำตอบ และใช้แสดงเนื้อหาภาพจากGoogle Maps ได้ ดูข้อมูลเพิ่มเติมเกี่ยวกับวิดเจ็ตตามบริบทได้ที่ วิดเจ็ตการเชื่อมโยงกับGoogle Maps widget ในเอกสารประกอบของGoogle Maps
ใช้พร็อพเพอร์ตี้ของสถานที่ในพรอมต์
ส่วนนี้แสดงรายการ พร็อพเพอร์ตี้ของสถานที่ ที่ใช้เพื่ออธิบายสถานที่
และใช้โดยการเชื่อมโยงกับ
ตัวอย่างพร็อพเพอร์ตี้ของสถานที่
รายการนี้แสดงตัวอย่างพร็อพเพอร์ตี้เกี่ยวกับสถานที่แบบเรียงตามตัวอักษรที่โมเดลใช้สร้างคำตอบได้
- ที่อยู่
- การรับสินค้าโดยไม่ต้องลงจากรถ
- บัตรเดบิต
- ระยะทาง
- ที่จอดรถแบบไม่เสียค่าใช้จ่าย
- ดนตรีสด
- เมนูสำหรับเด็ก
- เวลาทำการ
- ตัวเลือกการชำระเงิน (เช่น เงินสด หรือ บัตรเครดิต)
- คำตอบเกี่ยวกับสถานที่
- เป็นมิตรต่อสัตว์เลี้ยง
- เสิร์ฟเบียร์
- มีบริการอาหารมังสวิรัติ
- รองรับเก้าอี้รถเข็น
- Wifi
คำตอบเกี่ยวกับสถานที่ คือคำตอบจากการเชื่อมโยงกับ
ตัวอย่างพรอมต์ที่ใช้พร็อพเพอร์ตี้ของสถานที่
ตัวอย่างต่อไปนี้ใช้
พร็อพเพอร์ตี้ของสถานที่
ในพรอมต์เกี่ยวกับสถานที่ประเภทต่างๆ การเชื่อมโยงกับ
วางแผนอาหารค่ำกับครอบครัว: ดูว่าร้านอาหารเหมาะสำหรับ ครอบครัวหรือไม่ และร้านอาหารมีบริการที่สะดวกหรือไม่
- ตัวอย่างพรอมต์: ร้าน "The Italian Place" เหมาะสำหรับเด็กไหม และมี บริการซื้อกลับบ้านไหม ร้านนี้ได้คะแนนเท่าไร
ตรวจสอบความสามารถในการเข้าถึงสำหรับเพื่อน: ดูว่าสถานที่ตรงกับ ความต้องการด้านความสามารถในการเข้าถึงที่เฉพาะเจาะจงหรือไม่
- ตัวอย่างพรอมต์: ฉันอยากได้ร้านอาหารที่มีทางเข้าสำหรับผู้ใช้รถเข็น
ค้นหาสถานที่สำหรับของว่างยามดึก: ค้นหาสถานที่ที่เปิดให้บริการ อาหารมื้อหนึ่งในช่วงเวลาที่กำหนด
- ตัวอย่างพรอมต์: ร้าน "Burger Joint" เปิดอยู่ไหม ร้านนี้ให้บริการอาหารเย็นไหม_ เวลาทำการของร้านในวันศุกร์คือเมื่อไร
นัดลูกค้ามาจิบกาแฟ: ประเมินความเหมาะสมของคาเฟ่สำหรับการประชุมทางธุรกิจ โดยพิจารณาจากสิ่งอำนวยความสะดวก ข้อเสนอ และตัวเลือกการชำระเงิน
- ตัวอย่างพรอมต์: ร้าน "Cafe Central" มี Wifi ไหม ร้านนี้เสิร์ฟกาแฟไหม_ ระดับราคาของร้านเป็นอย่างไร และร้านรับบัตรเครดิตไหม
โปรดทราบว่าข้อมูลใน
วิธีการทำงานของการเชื่อมโยงกับ Google Maps
เมื่อคุณระบุเครื่องมือ GoogleMaps ให้โมเดล โมเดลจะจัดการเวิร์กโฟลว์ทั้งหมดของการค้นหา การประมวลผล และการอ้างอิงข้อมูลโดยอัตโนมัติ
เวิร์กโฟลว์ของ โมเดล มีดังนี้
รับพรอมต์: แอปของคุณจะส่งพรอมต์ไปยังโมเดล Gemini โดยเปิดใช้เครื่องมือ
GoogleMapsวิเคราะห์พรอมต์: โมเดลจะวิเคราะห์พรอมต์และพิจารณาว่า
Google Maps จะช่วยปรับปรุงคำตอบได้หรือไม่ เช่น หากพรอมต์ มีบริบททางภูมิศาสตร์ (เช่น "ร้านกาแฟใกล้ฉัน" "พิพิธภัณฑ์ใน ซานฟรานซิสโก")เรียกใช้เครื่องมือ: โมเดลจะเรียกใช้เครื่องมือการเชื่อมโยงกับ
Google Maps เมื่อรับรู้ถึงความตั้งใจทางภูมิศาสตร์ส่งคำค้นหาไปยัง
Google Maps : บริการการเชื่อมโยงกับGoogle Maps จะส่งคำค้นหาไปยังGoogle Maps เพื่อขอข้อมูลที่เกี่ยวข้อง (เช่น สถานที่ รีวิว รูปภาพ ที่อยู่ เวลาทำการ)คุณสามารถระบุละติจูดและลองจิจูดในการกำหนดค่าเครื่องมือ (หรือแม้แต่ในพรอมต์โดยตรง) เพื่อให้ได้ผลการค้นหาที่เกี่ยวข้องและปรับเปลี่ยนในแบบของคุณมากขึ้น
Google Maps เครื่องมือนี้เป็นเครื่องมือค้นหาแบบข้อความและทำงาน คล้ายกับการค้นหาในGoogle Maps โดยคำค้นหาในพื้นที่ ("ใกล้ฉัน") จะใช้พิกัด ส่วนคำค้นหาที่เฉพาะเจาะจงหรือไม่ใช่ในพื้นที่นั้นมีแนวโน้ม ที่จะไม่ได้รับผลกระทบจากสถานที่ตั้งที่ชัดเจนประมวลผลผลการค้นหา
Google Maps : โมเดลจะประมวลผลผลการค้นหาGoogle Maps และสร้างคำตอบสำหรับพรอมต์เดิมแสดง
Google Maps ผลการค้นหาที่เชื่อมโยง: โมเดลจะแสดงคำตอบสุดท้ายที่ ใช้งานง่ายซึ่งอิงตามผลการค้นหาGoogle Maps คำตอบนี้ประกอบด้วย- คำตอบที่เป็นข้อความของโมเดล
- ออบเจ็กต์
groundingMetadataที่มีผลการค้นหาและ แหล่งที่มาGoogle Maps - (Web SDK เท่านั้น) `googleMapsWidgetContextToken` (ไม่บังคับ) ซึ่งช่วยให้คุณ
แสดงวิดเจ็ตตามบริบทของ
Google Maps ในแอปเพื่อการโต้ตอบด้วยภาพได้ ดูข้อมูลเพิ่มเติมเกี่ยวกับวิดเจ็ตตามบริบทได้ที่ วิดเจ็ตการเชื่อมโยงกับGoogle Maps ในเอกสารประกอบGoogle Maps
โปรดทราบว่าการระบุ groundingMetadata จึง
จึง ไม่ใช่
ทำความเข้าใจผลการค้นหาที่เชื่อมโยง
หากโมเดลเชื่อมโยงคำตอบกับผลการค้นหา groundingMetadata ที่มี Structured Data ซึ่ง
จำเป็นสำหรับการยืนยันการอ้างสิทธิ์และการสร้างประสบการณ์การใช้งานแหล่งที่มาที่สมบูรณ์ใน
แอปพลิเคชัน
ออบเจ็กต์ groundingMetadata ใน
groundingChunks: อาร์เรย์ของออบเจ็กต์ที่มีแหล่งที่มาmaps(uri,placeIdและtitle)groundingSupports: อาร์เรย์ของ Chunk เพื่อเชื่อมต่อtextคำตอบของโมเดลกับแหล่งที่มาในgroundingChunksChunk แต่ละรายการจะลิงก์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
คุณจะได้รับแหล่งที่มาใน
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จากคำตอบ
คุณยุบมุมมองของแหล่งที่มาได้
นอกจากนี้ คุณยังปรับปรุงตัวอย่างลิงก์ด้วยเนื้อหาเพิ่มเติมได้ เช่น
- Favicon ที่แทรกไว้ก่อนการระบุแหล่งที่มาแบบข้อความ
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;
}
การแคชโทเค็นบริบทและรหัสสถานที่
_ผลการค้นหาที่เชื่อมโยงกับ Google Maps_
- (Web SDK เท่านั้น)
googleMapsWidgetContextToken placeId
ข้อจำกัดในการแคชในข้อกำหนดการเชื่อมต่อแหล่งข้อมูลกับ Google Maps จะไม่มีผลกับข้อมูลนี้
กิจกรรมและดินแดนที่ไม่อนุญาต
การเชื่อมโยงกับ
คุณจะไม่ใช้การเชื่อมโยงกับ
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 ให้เป็นไปตามข้อกำหนดเหล่านี้
การกำหนดราคาและขีดจำกัดอัตรา
การกำหนดราคาของการเชื่อมโยงกับ
โปรดอ่านรายละเอียดเกี่ยวกับการกำหนดราคา ความพร้อมให้บริการของโมเดล และขีดจำกัดสำหรับ
การเชื่อมโยงกับ