การเชื่อมต่อแหล่งข้อมูลกับ Google Maps จะเชื่อมโยงความสามารถในการสร้างเนื้อหาของ Gemini กับข้อมูลที่สมบูรณ์ เป็นข้อเท็จจริง และเป็นข้อมูลล่าสุดของ Google Maps ฟีเจอร์นี้ช่วยให้นักพัฒนาแอปสามารถผสานรวมฟังก์ชันการทำงานที่รับรู้ตำแหน่งลงในแอปพลิเคชันได้อย่างง่ายดาย เมื่อคำค้นหาของผู้ใช้มีบริบทที่เกี่ยวข้องกับข้อมูล Maps โมเดล Gemini จะใช้ประโยชน์จาก Google Maps เพื่อให้คำตอบที่ถูกต้องตามข้อเท็จจริงและเป็นข้อมูลล่าสุดซึ่งเกี่ยวข้องกับสถานที่ที่ผู้ใช้ระบุหรือพื้นที่ทั่วไป
- คำตอบที่แม่นยำและรับรู้ตำแหน่ง: ใช้ประโยชน์จากข้อมูลที่ครอบคลุมและเป็นปัจจุบันของ Google Maps สำหรับคำค้นหาที่เฉพาะเจาะจงทางภูมิศาสตร์
- การปรับเปลี่ยนในแบบของผู้ใช้ที่มีประสิทธิภาพมากขึ้น: ปรับแต่งคำแนะนำและข้อมูลตามสถานที่ที่ผู้ใช้ระบุ
- ข้อมูลและวิดเจ็ตตามบริบท: โทเค็นบริบทเพื่อแสดงวิดเจ็ต Google Maps แบบโต้ตอบควบคู่ไปกับเนื้อหาที่สร้างขึ้น
เริ่มต้นใช้งาน
ตัวอย่างนี้แสดงวิธีผสานรวมการเชื่อมต่อแหล่งข้อมูลกับ Google Maps เข้ากับแอปพลิเคชันเพื่อแสดงคำตอบที่ถูกต้องและรับรู้ตำแหน่งสำหรับคำค้นหาของผู้ใช้ พรอมต์จะขอคำแนะนำในพื้นที่พร้อมสถานที่ของผู้ใช้ (ไม่บังคับ) ซึ่งช่วยให้โมเดล Gemini ใช้ข้อมูล Google Maps ได้
Python
from google import genai
from google.genai import types
client = genai.Client()
prompt = "What are the best Italian restaurants within a 15-minute walk from here?"
response = client.models.generate_content(
model='gemini-3-flash-preview',
contents=prompt,
config=types.GenerateContentConfig(
# Turn on grounding with Google Maps
tools=[types.Tool(google_maps=types.GoogleMaps())],
# Optionally provide the relevant location context (this is in Los Angeles)
tool_config=types.ToolConfig(retrieval_config=types.RetrievalConfig(
lat_lng=types.LatLng(
latitude=34.050481, longitude=-118.248526))),
),
)
print("Generated Response:")
print(response.text)
if grounding := response.candidates[0].grounding_metadata:
if grounding.grounding_chunks:
print('-' * 40)
print("Sources:")
for chunk in grounding.grounding_chunks:
print(f'- [{chunk.maps.title}]({chunk.maps.uri})')
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function generateContentWithMapsGrounding() {
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: "What are the best Italian restaurants within a 15-minute walk from here?",
config: {
// Turn on grounding with Google Maps
tools: [{ googleMaps: {} }],
toolConfig: {
retrievalConfig: {
// Optionally provide the relevant location context (this is in Los Angeles)
latLng: {
latitude: 34.050481,
longitude: -118.248526,
},
},
},
},
});
console.log("Generated Response:");
console.log(response.text);
const grounding = response.candidates[0]?.groundingMetadata;
if (grounding?.groundingChunks) {
console.log("-".repeat(40));
console.log("Sources:");
for (const chunk of grounding.groundingChunks) {
if (chunk.maps) {
console.log(`- [${chunk.maps.title}](${chunk.maps.uri})`);
}
}
}
}
generateContentWithMapsGrounding();
REST
curl -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent' \
-H 'Content-Type: application/json' \
-H "x-goog-api-key: ${GEMINI_API_KEY}" \
-d '{
"contents": [{
"role": "user",
"parts": [{
"text": "What are the best Italian restaurants within a 15-minute walk from here?"
}]
}],
"tools": [{"googleMaps": {}}],
"toolConfig": {
"retrievalConfig": {
"latLng": {"latitude": 34.050481, "longitude": -118.248526}
}
}
}'
วิธีการทำงานของการเชื่อมต่อแหล่งข้อมูลกับ Google Maps
การเชื่อมต่อแหล่งข้อมูลกับ Google Maps จะผสานรวม Gemini API กับระบบนิเวศทางภูมิศาสตร์ของ Google โดยใช้ Maps API เป็นแหล่งข้อมูล เมื่อคำค้นหาของผู้ใช้มีบริบททางภูมิศาสตร์ โมเดล Gemini จะเรียกใช้เครื่องมือการเชื่อมต่อแหล่งข้อมูลกับ Google Maps ได้ จากนั้นโมเดลจะสร้างคำตอบที่อิงตามข้อมูล Google Maps ที่เกี่ยวข้องกับสถานที่ที่ระบุ
กระบวนการโดยทั่วไปมีดังนี้
- คำค้นหาของผู้ใช้: ผู้ใช้ส่งคำค้นหาไปยังแอปพลิเคชันของคุณ ซึ่งอาจมีบริบททางภูมิศาสตร์ (เช่น "ร้านกาแฟใกล้ฉัน" "พิพิธภัณฑ์ในซานฟรานซิสโก")
- การเรียกใช้เครื่องมือ: โมเดล Gemini จะเรียกใช้เครื่องมือการเชื่อมต่อแหล่งข้อมูลกับ Google Maps เมื่อรับรู้ถึงความตั้งใจทางภูมิศาสตร์ คุณจะระบุ
latitudeและlongitudeของผู้ใช้ให้กับเครื่องมือนี้หรือไม่ก็ได้ เครื่องมือนี้เป็นเครื่องมือค้นหาแบบข้อความและทำงานคล้ายกับการค้นหาใน Maps โดยคำค้นหาในพื้นที่ ("ใกล้ฉัน") จะใช้พิกัด ส่วนคำค้นหาที่เฉพาะเจาะจงหรือไม่ใช่ในพื้นที่นั้นมีแนวโน้มที่จะไม่ได้รับผลกระทบจากสถานที่ที่ระบุ - การดึงข้อมูล: บริการการเชื่อมต่อแหล่งข้อมูลกับ Google Maps จะค้นหาข้อมูลที่เกี่ยวข้องจาก Google Maps (เช่น สถานที่ รีวิว รูปภาพ ที่อยู่ เวลาทำการ)
- การสร้างเนื้อหาที่อิงตามแหล่งข้อมูล: ระบบจะใช้ข้อมูล Maps ที่ดึงมาเพื่อแจ้งคำตอบของโมเดล Gemini ซึ่งจะช่วยให้คำตอบถูกต้องตามข้อเท็จจริงและเกี่ยวข้อง
- คำตอบและโทเค็นวิดเจ็ต: โมเดลจะแสดงคำตอบแบบข้อความ ซึ่งรวมถึงการอ้างอิงแหล่งข้อมูล Google Maps นอกจากนี้ การตอบกลับของ API อาจมี
google_maps_widget_context_tokenด้วย ซึ่งช่วยให้นักพัฒนาแอปแสดงวิดเจ็ต Google Maps ตามบริบทในแอปพลิเคชันเพื่อการโต้ตอบแบบเห็นภาพได้
เหตุผลและเวลาที่ควรใช้การเชื่อมต่อแหล่งข้อมูลกับ Google Maps
การเชื่อมต่อแหล่งข้อมูลกับ Google Maps เหมาะสำหรับแอปพลิเคชันที่ต้องใช้ข้อมูลที่ถูกต้อง เป็นข้อมูลล่าสุด และเฉพาะเจาะจงสถานที่ ฟีเจอร์นี้ช่วยยกระดับประสบการณ์ของผู้ใช้ด้วยการแสดงเนื้อหาที่เกี่ยวข้องและปรับเปลี่ยนในแบบของผู้ใช้ ซึ่งได้รับการสนับสนุนจากฐานข้อมูลที่ครอบคลุมของ Google Maps ที่มีสถานที่มากกว่า 250 ล้านแห่งทั่วโลก
คุณควรใช้การเชื่อมต่อแหล่งข้อมูลกับ Google Maps เมื่อแอปพลิเคชันต้องดำเนินการต่อไปนี้
- แสดงคำตอบที่สมบูรณ์และถูกต้องสำหรับคำถามที่เฉพาะเจาะจงทางภูมิศาสตร์
- สร้างผู้ช่วยวางแผนการเดินทางและ Local Guides แบบสนทนา
- แนะนำจุดที่น่าสนใจตามสถานที่และการกำหนดค่าของผู้ใช้ เช่น ร้านอาหารหรือร้านค้า
- สร้างประสบการณ์ที่รับรู้ตำแหน่งสำหรับบริการโซเชียล บริการค้าปลีก หรือบริการจัดส่งอาหาร
การเชื่อมต่อแหล่งข้อมูลกับ Google Maps เหมาะอย่างยิ่งสำหรับ Use Case ที่ระยะทางและข้อมูลข้อเท็จจริงปัจจุบันมีความสำคัญอย่างยิ่ง เช่น การค้นหา "ร้านกาแฟที่ดีที่สุดใกล้ฉัน" หรือการดูเส้นทาง
เมธอดและพารามิเตอร์ของ API
การเชื่อมต่อแหล่งข้อมูลกับ Google Maps จะแสดงผ่าน Gemini API เป็นเครื่องมือภายใน
เมธอด generateContent คุณเปิดใช้และกำหนดค่า
การเชื่อมต่อแหล่งข้อมูลกับ Google Maps ได้โดยใส่
googleMaps ออบเจ็กต์ในพารามิเตอร์ tools ของ
คำขอ
JSON
{
"contents": [{
"parts": [
{"text": "Restaurants near Times Square."}
]
}],
"tools": { "googleMaps": {} }
}
นอกจากนี้ เครื่องมือ googleMaps ยังยอมรับพารามิเตอร์
บูลีน enableWidget ซึ่งใช้เพื่อควบคุมว่าจะแสดงฟิลด์
googleMapsWidgetContextToken
ในการตอบกลับหรือไม่ คุณสามารถใช้พารามิเตอร์นี้เพื่อแสดงวิดเจ็ตสถานที่ตามบริบทได้
JSON
{
"contents": [{
"parts": [
{"text": "Restaurants near Times Square."}
]
}],
"tools": { "googleMaps": { "enableWidget": true } }
}
นอกจากนี้ เครื่องมือยังรองรับการส่งสถานที่ตามบริบทเป็น toolConfig ด้วย
JSON
{
"contents": [{
"parts": [
{"text": "Restaurants near here."}
]
}],
"tools": { "googleMaps": {} },
"toolConfig": {
"retrievalConfig": {
"latLng": {
"latitude": 40.758896,
"longitude": -73.985130
}
}
}
}
ทำความเข้าใจการตอบกลับของการเชื่อมต่อแหล่งข้อมูล
เมื่อการตอบกลับเชื่อมต่อแหล่งข้อมูลกับข้อมูล Google Maps ได้สำเร็จ การตอบกลับ
จะมี groundingMetadata ฟิลด์
ข้อมูลที่มีโครงสร้างนี้มีความสำคัญอย่างยิ่งต่อการยืนยันการอ้างสิทธิ์และการสร้างประสบการณ์การอ้างอิงที่สมบูรณ์ในแอปพลิเคชัน รวมถึงการปฏิบัติตามข้อกำหนดในการใช้งานบริการ
JSON
{
"candidates": [
{
"content": {
"parts": [
{
"text": "CanteenM is an American restaurant with..."
}
],
"role": "model"
},
"groundingMetadata": {
"groundingChunks": [
{
"maps": {
"uri": "https://maps.google.com/?cid=13100894621228039586",
"title": "Heaven on 7th Marketplace",
"placeId": "places/ChIJ0-zA1vBZwokRon0fGj-6z7U"
},
// repeated ...
}
],
"groundingSupports": [
{
"segment": {
"startIndex": 0,
"endIndex": 79,
"text": "CanteenM is an American restaurant with a 4.6-star rating and is open 24 hours."
},
"groundingChunkIndices": [0]
},
// repeated ...
],
"webSearchQueries": [
"restaurants near me"
],
"googleMapsWidgetContextToken": "widgetcontent/..."
}
}
]
}
Gemini API จะแสดงข้อมูลต่อไปนี้พร้อมกับ
groundingMetadata
groundingChunks: อาร์เรย์ของออบเจ็กต์ที่มีแหล่งข้อมูลmaps(uri,placeIdและtitle)groundingSupports: อาร์เรย์ของ Chunk เพื่อเชื่อมต่อข้อความตอบกลับของโมเดลกับแหล่งข้อมูลในgroundingChunksChunk แต่ละรายการจะลิงก์ช่วงข้อความ (กำหนดโดยstartIndexและendIndex) กับgroundingChunkIndicesอย่างน้อย 1 รายการ ซึ่งเป็นคีย์สำคัญในการสร้างการอ้างอิงแบบอินไลน์googleMapsWidgetContextToken: โทเค็นข้อความที่ใช้แสดงวิดเจ็ตสถานที่ตามบริบท ได้
ดูข้อมูลโค้ดที่แสดงวิธีแสดงการอ้างอิงแบบอินไลน์ในข้อความได้ใน ตัวอย่าง ในเอกสารประกอบการเชื่อมต่อแหล่งข้อมูลกับ Google Search
แสดงวิดเจ็ตตามบริบทของ Google Maps
หากต้องการใช้ googleMapsWidgetContextToken ที่แสดงผล คุณต้อง โหลด
Google Maps JavaScript
API
กรณีการใช้งาน
การเชื่อมต่อแหล่งข้อมูลกับ Google Maps รองรับกรณีการใช้งานที่รับรู้ตำแหน่งได้หลากหลาย ตัวอย่างต่อไปนี้แสดงวิธีที่พรอมต์และพารามิเตอร์ต่างๆ ใช้ประโยชน์จากการเชื่อมต่อแหล่งข้อมูลกับ Google Maps ได้ ข้อมูลในผลการค้นหาที่อิงตามแหล่งข้อมูลของ Google Maps อาจแตกต่างจากสภาพจริง
การจัดการคำถามที่เฉพาะเจาะจงสถานที่
ถามคำถามโดยละเอียดเกี่ยวกับสถานที่ที่เฉพาะเจาะจงเพื่อรับคำตอบที่อิงตามรีวิวของผู้ใช้ Google และข้อมูล Maps อื่นๆ
Python
from google import genai
from google.genai import types
client = genai.Client()
prompt = "Is there a cafe near the corner of 1st and Main that has outdoor seating?"
response = client.models.generate_content(
model='gemini-3-flash-preview',
contents=prompt,
config=types.GenerateContentConfig(
# Turn on the Maps tool
tools=[types.Tool(google_maps=types.GoogleMaps())],
# Provide the relevant location context (this is in Los Angeles)
tool_config=types.ToolConfig(retrieval_config=types.RetrievalConfig(
lat_lng=types.LatLng(
latitude=34.050481, longitude=-118.248526))),
),
)
print("Generated Response:")
print(response.text)
if grounding := response.candidates[0].grounding_metadata:
if chunks := grounding.grounding_chunks:
print('-' * 40)
print("Sources:")
for chunk in chunks:
print(f'- [{chunk.maps.title}]({chunk.maps.uri})')
```
Javascript
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({});
async function run() {
const prompt = "Is there a cafe near the corner of 1st and Main that has outdoor seating?";
const response = await ai.models.generateContent({
model: 'gemini-3-flash-preview',
contents: prompt,
config: {
// Turn on the Maps tool
tools: [{googleMaps: {}}],
// Provide the relevant location context (this is in Los Angeles)
toolConfig: {
retrievalConfig: {
latLng: {
latitude: 34.050481,
longitude: -118.248526
}
}
}
},
});
console.log("Generated Response:");
console.log(response.text);
const chunks = response.candidates[0].groundingMetadata?.groundingChunks;
if (chunks) {
console.log('-'.repeat(40));
console.log("Sources:");
for (const chunk of chunks) {
if (chunk.maps) {
console.log(`- [${chunk.maps.title}](${chunk.maps.uri})`);
}
}
}
}
run();
REST
curl -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent' \
-H 'Content-Type: application/json' \
-H "x-goog-api-key: ${GEMINI_API_KEY}" \
-d '{
"contents": [{
"role": "user",
"parts": [{
"text": "Is there a cafe near the corner of 1st and Main that has outdoor seating?"
}]
}],
"tools": [{"googleMaps": {}}],
"toolConfig": {
"retrievalConfig": {
"latLng": {"latitude": 34.050481, "longitude": -118.248526}
}
}
}'
การแสดงการปรับเปลี่ยนในแบบของผู้ใช้ตามสถานที่
รับคำแนะนำที่ปรับให้เหมาะกับค่ากำหนดของผู้ใช้และพื้นที่ทางภูมิศาสตร์ที่เฉพาะเจาะจง
Python
from google import genai
from google.genai import types
client = genai.Client()
prompt = "Which family-friendly restaurants near here have the best playground reviews?"
response = client.models.generate_content(
model='gemini-3-flash-preview',
contents=prompt,
config=types.GenerateContentConfig(
tools=[types.Tool(google_maps=types.GoogleMaps())],
tool_config=types.ToolConfig(retrieval_config=types.RetrievalConfig(
# Provide the location as context; this is Austin, TX.
lat_lng=types.LatLng(
latitude=30.2672, longitude=-97.7431))),
),
)
print("Generated Response:")
print(response.text)
if grounding := response.candidates[0].grounding_metadata:
if chunks := grounding.grounding_chunks:
print('-' * 40)
print("Sources:")
for chunk in chunks:
print(f'- [{chunk.maps.title}]({chunk.maps.uri})')
Javascript
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({});
async function run() {
const prompt = "Which family-friendly restaurants near here have the best playground reviews?";
const response = await ai.models.generateContent({
model: 'gemini-3-flash-preview',
contents: prompt,
config: {
tools: [{googleMaps: {}}],
toolConfig: {
retrievalConfig: {
// Provide the location as context; this is Austin, TX.
latLng: {
latitude: 30.2672,
longitude: -97.7431
}
}
}
},
});
console.log("Generated Response:");
console.log(response.text);
const chunks = response.candidates[0].groundingMetadata?.groundingChunks;
if (chunks) {
console.log('-'.repeat(40));
console.log("Sources:");
for (const chunk of chunks) {
if (chunk.maps) {
console.log(`- [${chunk.maps.title}](${chunk.maps.uri})`);
}
}
}
}
run();
REST
curl -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent' \
-H 'Content-Type: application/json' \
-H "x-goog-api-key: ${GEMINI_API_KEY}" \
-d '{
"contents": [{
"role": "user",
"parts": [{
"text": "Which family-friendly restaurants near here have the best playground reviews?"
}],
}],
"tools": [{"googleMaps": {}}],
"toolConfig": {
"retrievalConfig": {
"latLng": {"latitude": 30.2672, "longitude": -97.7431}
}
}
}'
การช่วยเหลือในการวางแผนการเดินทาง
สร้างแผนการเดินทางหลายวันพร้อมเส้นทางและข้อมูลเกี่ยวกับสถานที่ต่างๆ ซึ่งเหมาะสำหรับแอปพลิเคชันการเดินทาง
ในตัวอย่างนี้ ระบบได้ขอ googleMapsWidgetContextToken โดยการเปิดใช้วิดเจ็ตในเครื่องมือ Google Maps เมื่อเปิดใช้แล้ว คุณจะใช้โทเค็นที่แสดงผล
เพื่อแสดงวิดเจ็ตสถานที่ตามบริบทโดยใช้
<gmp-places-contextual> component
จาก Google Maps JavaScript API ได้
Python
from google import genai
from google.genai import types
client = genai.Client()
prompt = "Plan a day in San Francisco for me. I want to see the Golden Gate Bridge, visit a museum, and have a nice dinner."
response = client.models.generate_content(
model='gemini-3-flash-preview',
contents=prompt,
config=types.GenerateContentConfig(
tools=[types.Tool(google_maps=types.GoogleMaps(enable_widget=True))],
tool_config=types.ToolConfig(retrieval_config=types.RetrievalConfig(
# Provide the location as context, this is in San Francisco.
lat_lng=types.LatLng(
latitude=37.78193, longitude=-122.40476))),
),
)
print("Generated Response:")
print(response.text)
if grounding := response.candidates[0].grounding_metadata:
if grounding.grounding_chunks:
print('-' * 40)
print("Sources:")
for chunk in grounding.grounding_chunks:
print(f'- [{chunk.maps.title}]({chunk.maps.uri})')
if widget_token := grounding.google_maps_widget_context_token:
print('-' * 40)
print(f'<gmp-place-contextual context-token="{widget_token}"></gmp-place-contextual>')
Javascript
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({});
async function run() {
const prompt = "Plan a day in San Francisco for me. I want to see the Golden Gate Bridge, visit a museum, and have a nice dinner.";
const response = await ai.models.generateContent({
model: 'gemini-3-flash-preview',
contents: prompt,
config: {
tools: [{googleMaps: {enableWidget: true}}],
toolConfig: {
retrievalConfig: {
// Provide the location as context, this is in San Francisco.
latLng: {
latitude: 37.78193,
longitude: -122.40476
}
}
}
},
});
console.log("Generated Response:");
console.log(response.text);
const groundingMetadata = response.candidates[0]?.groundingMetadata;
if (groundingMetadata) {
if (groundingMetadata.groundingChunks) {
console.log('-'.repeat(40));
console.log("Sources:");
for (const chunk of groundingMetadata.groundingChunks) {
if (chunk.maps) {
console.log(`- [${chunk.maps.title}](${chunk.maps.uri})`);
}
}
}
if (groundingMetadata.googleMapsWidgetContextToken) {
console.log('-'.repeat(40));
document.body.insertAdjacentHTML('beforeend', `<gmp-place-contextual context-token="${groundingMetadata.googleMapsWidgetContextToken}`"></gmp-place-contextual>`);
}
}
}
run();
REST
curl -X POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent' \
-H 'Content-Type: application/json' \
-H "x-goog-api-key: ${GEMINI_API_KEY}" \
-d '{
"contents": [{
"role": "user",
"parts": [{
"text": "Plan a day in San Francisco for me. I want to see the Golden Gate Bridge, visit a museum, and have a nice dinner."
}]
}],
"tools": [{"googleMaps": {"enableWidget":"true"}}],
"toolConfig": {
"retrievalConfig": {
"latLng": {"latitude": 37.78193, "longitude": -122.40476}
}
}
}'
เมื่อแสดงผลแล้ว วิดเจ็ตจะมีลักษณะดังนี้
ข้อกำหนดในการใช้งานบริการ
ส่วนนี้อธิบายข้อกำหนดในการใช้งานบริการสำหรับการเชื่อมต่อแหล่งข้อมูลกับ Google Maps
แจ้งให้ผู้ใช้ทราบเกี่ยวกับการใช้แหล่งข้อมูล Google Maps
ผลการค้นหาที่อิงตามแหล่งข้อมูลของ Google Maps แต่ละรายการจะมีแหล่งข้อมูลใน groundingChunks ที่รองรับการตอบกลับแต่ละรายการ นอกจากนี้ ระบบยังแสดงข้อมูลเมตาต่อไปนี้ด้วย
- URI ต้นทาง
- title
- รหัส
เมื่อแสดงผลการค้นหาจากการเชื่อมต่อแหล่งข้อมูลกับ Google Maps คุณต้องระบุแหล่งข้อมูล Google Maps ที่เกี่ยวข้องและแจ้งให้ผู้ใช้ทราบดังต่อไปนี้
- แหล่งข้อมูล Google Maps ต้องอยู่ต่อจากเนื้อหาที่สร้างขึ้นซึ่งแหล่งข้อมูลรองรับทันที เนื้อหาที่สร้างขึ้นนี้เรียกอีกอย่างว่าผลการค้นหาที่อิงตามแหล่งข้อมูลของ Google Maps
- แหล่งข้อมูล Google Maps ต้องดูได้ภายใน 1 การโต้ตอบของผู้ใช้
แสดงแหล่งข้อมูล Google Maps พร้อมลิงก์ Google Maps
สำหรับแหล่งข้อมูลแต่ละรายการใน groundingChunks และใน grounding_chunks.maps.placeAnswerSources.reviewSnippets คุณต้องสร้างการแสดงตัวอย่างลิงก์ตามข้อกำหนดต่อไปนี้
- ระบุแหล่งที่มาแต่ละรายการเป็น Google Maps ตามหลักเกณฑ์การระบุแหล่งที่มาด้วยข้อความของ Google Maps
- แสดงชื่อแหล่งข้อมูลที่ระบุไว้ในการตอบกลับ
- ลิงก์ไปยังแหล่งข้อมูลโดยใช้
uriหรือgoogleMapsUriจากการตอบกลับ
รูปภาพเหล่านี้แสดงข้อกำหนดขั้นต่ำสำหรับการแสดงแหล่งข้อมูลและลิงก์ Google Maps
คุณสามารถยุบมุมมองของแหล่งข้อมูลได้
ไม่บังคับ: ปรับปรุงการแสดงตัวอย่างลิงก์ด้วยเนื้อหาเพิ่มเติม เช่น
- แทรก Favicon ของ Google Maps ไว้ก่อนการระบุแหล่งที่มาด้วยข้อความของ Google Maps
- รูปภาพจาก URL แหล่งที่มา (
og:image)
ดูข้อมูลเพิ่มเติมเกี่ยวกับผู้ให้บริการข้อมูล Google Maps บางรายและ ข้อกำหนดด้านใบอนุญาตได้ที่ ประกาศทางกฎหมายของ Google Maps และ Google Earth
หลักเกณฑ์การระบุแหล่งที่มาด้วยข้อความของ Google Maps
เมื่อระบุแหล่งที่มาเป็น Google Maps ในข้อความ ให้ทำตามหลักเกณฑ์ต่อไปนี้
- อย่าแก้ไขข้อความ Google Maps ในลักษณะใดก็ตาม
- อย่าเปลี่ยนการใช้อักษรตัวพิมพ์ใหญ่และตัวพิมพ์เล็กของ Google Maps
- อย่าขึ้นบรรทัดใหม่สำหรับ Google Maps
- อย่าแปล Google Maps เป็นภาษาอื่น
- ป้องกันไม่ให้เบราว์เซอร์แปล Google Maps โดยใช้แอตทริบิวต์ HTML translate="no"
- จัดรูปแบบข้อความ Google Maps ตามที่อธิบายไว้ในตารางต่อไปนี้
| พร็อพเพอร์ตี้ | รูปแบบ |
|---|---|
Font family |
Roboto คุณจะโหลดแบบอักษรหรือไม่ก็ได้ |
Fallback font family |
แบบอักษรเนื้อหา Sans Serif ใดก็ได้ที่ใช้ในผลิตภัณฑ์ของคุณอยู่แล้ว หรือ "Sans-Serif" เพื่อเรียกใช้แบบอักษรเริ่มต้นของระบบ |
Font style |
ปกติ |
Font weight |
400 |
Font color |
สีขาว สีดำ (#1F1F1F) หรือสีเทา (#5E5E5E) รักษาระดับความแตกต่างที่เข้าถึงได้ (4.5:1) กับพื้นหลัง |
Font size |
|
Spacing |
ปกติ |
ตัวอย่าง CSS
CSS ต่อไปนี้จะแสดงผล Google Maps ด้วยรูปแบบตัวอักษรและสีที่เหมาะสมบนพื้นหลังสีขาวหรือสีอ่อน
CSS
@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');
.GMP-attribution {
font-family: Roboto, Sans-Serif;
font-style: normal;
font-weight: 400;
font-size: 1rem;
letter-spacing: normal;
white-space: nowrap;
color: #5e5e5e;
}
โทเค็นบริบท, รหัสสถานที่ และรหัสรีวิว
ข้อมูล Google Maps มีโทเค็นบริบท, รหัสสถานที่ และรหัสรีวิว คุณอาจแคช จัดเก็บ และส่งออกข้อมูลการตอบกลับต่อไปนี้
googleMapsWidgetContextTokenplaceIdreviewId
ข้อจำกัดในการแคชในข้อกำหนดการเชื่อมต่อแหล่งข้อมูลกับ Google Maps จะไม่มีผลบังคับใช้
กิจกรรมและเขตแดนที่ไม่อนุญาต
การเชื่อมต่อแหล่งข้อมูลกับ Google Maps มีข้อจำกัดเพิ่มเติมสำหรับเนื้อหาและกิจกรรมบางอย่างเพื่อรักษาแพลตฟอร์มให้ปลอดภัยและเชื่อถือได้ นอกเหนือจากข้อจำกัดในการใช้งานที่ระบุไว้ในข้อกำหนดแล้ว คุณจะต้องไม่ดำเนินการต่อไปนี้
- คุณจะไม่ใช้การเชื่อมต่อแหล่งข้อมูลกับ Google Maps สำหรับกิจกรรมที่มีความเสี่ยงสูง ซึ่งรวมถึงบริการตอบสนองต่อเหตุฉุกเฉิน
คุณจะไม่เผยแพร่หรือทำการตลาดแอปพลิเคชันที่ให้บริการการเชื่อมต่อแหล่งข้อมูลกับ Google Maps ในเขตแดนที่ไม่อนุญาต เขตแดนที่ไม่อนุญาตในปัจจุบันมีดังนี้
- จีน
- ไครเมีย
- คิวบา
- สาธารณรัฐประชาชนดอแนตสก์
- อิหร่าน
- สาธารณรัฐประชาชนลูฮันสก์
- เกาหลีเหนือ
- ซีเรีย
- เวียดนาม
รายการนี้อาจมีการอัปเดตเป็นครั้งคราว
แนวทางปฏิบัติแนะนำ
- ระบุสถานที่ของผู้ใช้: เพื่อให้ได้คำตอบที่เกี่ยวข้องและปรับเปลี่ยนในแบบของผู้ใช้มากที่สุด ให้ใส่
user_location(ละติจูดและลองจิจูด) ในการกำหนดค่าgoogleMapsGroundingเสมอเมื่อทราบสถานที่ของผู้ใช้ - แสดงวิดเจ็ตตามบริบทของ Google Maps: ระบบจะแสดงวิดเจ็ตตามบริบทโดยใช้โทเค็นบริบท
googleMapsWidgetContextTokenซึ่งแสดงผลในการตอบกลับของ Gemini API และใช้แสดงเนื้อหาแบบเห็นภาพจาก Google Maps ได้ ดูข้อมูลเพิ่มเติมเกี่ยวกับวิดเจ็ตตามบริบทได้ที่ วิดเจ็ตการเชื่อมต่อแหล่งข้อมูลกับ Google Maps ในคู่มือนักพัฒนาซอฟต์แวร์ Google - แจ้งผู้ใช้ปลายทาง: แจ้งให้ผู้ใช้ปลายทางทราบอย่างชัดเจนว่าระบบใช้ข้อมูล Google Maps เพื่อตอบคำค้นหาของผู้ใช้ โดยเฉพาะอย่างยิ่งเมื่อเปิดใช้เครื่องมือ
- ตรวจสอบเวลาในการตอบสนอง: สำหรับแอปพลิเคชันแบบสนทนา ให้ตรวจสอบว่าเวลาในการตอบสนอง P95 สำหรับคำตอบที่อิงตามแหล่งข้อมูลยังคงอยู่ในเกณฑ์ที่ยอมรับได้เพื่อรักษาประสบการณ์การใช้งานที่ราบรื่น
- ปิดเมื่อไม่จำเป็น: การเชื่อมต่อแหล่งข้อมูลกับ Google Maps จะปิดอยู่โดยค่าเริ่มต้น ให้เปิดใช้ (
"tools": [{"googleMaps": {}}]) เฉพาะเมื่อคำค้นหามี บริบททางภูมิศาสตร์ที่ชัดเจน เพื่อเพิ่มประสิทธิภาพและลดค่าใช้จ่าย
ข้อจำกัด
- ขอบเขตทางภูมิศาสตร์: การเชื่อมต่อแหล่งข้อมูลกับ Google Maps พร้อมให้บริการทั่วโลก
- การรองรับโมเดล: ดูส่วน โมเดลที่รองรับ
- อินพุต/เอาต์พุตหลายรูปแบบ: ปัจจุบันการเชื่อมต่อแหล่งข้อมูลกับ Google Maps ยังไม่รองรับอินพุตหรือเอาต์พุตหลายรูปแบบนอกเหนือจากข้อความและวิดเจ็ตแผนที่ตามบริบท
- สถานะเริ่มต้น: เครื่องมือการเชื่อมต่อแหล่งข้อมูลกับ Google Maps จะปิดอยู่โดยค่าเริ่มต้น คุณต้องเปิดใช้เครื่องมือนี้อย่างชัดเจนในคำขอ API
การกำหนดราคาและขีดจำกัดอัตรา
การกำหนดราคาการเชื่อมต่อแหล่งข้อมูลกับ Google Maps จะอิงตามคำค้นหา อัตราปัจจุบันคือ $25 / 1,000 พรอมต์ที่อิงตามแหล่งข้อมูล นอกจากนี้ ระดับฟรียังมีคำขอให้ใช้ได้สูงสุด 500 รายการต่อวัน ระบบจะนับคำขอรวมกับโควต้าก็ต่อเมื่อพรอมต์แสดงผลการค้นหาที่อิงตามแหล่งข้อมูลของ Google Maps อย่างน้อย 1 รายการ (เช่น ผลการค้นหาที่มีแหล่งข้อมูล Google Maps อย่างน้อย 1 รายการ) ได้สำเร็จ หากส่งคำค้นหาหลายรายการไปยัง Google Maps จากคำขอเดียว ระบบจะนับเป็น 1 คำขอรวมกับขีดจำกัดอัตรา
ดูข้อมูลการกำหนดราคารายละเอียดได้ที่หน้าการกำหนดราคา Gemini API
โมเดลที่รองรับ
โมเดลต่อไปนี้รองรับการเชื่อมต่อแหล่งข้อมูลกับ Google Maps
| รุ่น | การเชื่อมต่อแหล่งข้อมูลกับ Google Maps |
|---|---|
| Gemini 3.1 Pro (เวอร์ชันตัวอย่าง) | ✔️ |
| Gemini 3.1 Flash-Lite (เวอร์ชันตัวอย่าง) | ✔️ |
| Gemini 3 Flash (เวอร์ชันตัวอย่าง) | ✔️ |
| Gemini 2.5 Pro | ✔️ |
| Gemini 2.5 Flash | ✔️ |
| Gemini 2.5 Flash-Lite | ✔️ |
| Gemini 2.0 Flash | ✔️ |
ชุดค่าผสมของเครื่องมือที่รองรับ
โมเดล Gemini 3 รองรับการรวมเครื่องมือในตัว (เช่น การเชื่อมต่อแหล่งข้อมูลกับ Google Maps) กับเครื่องมือที่กำหนดเอง (การเรียกใช้ฟังก์ชัน) ดูข้อมูลเพิ่มเติมได้ในหน้า ชุดค่าผสมของเครื่องมือ
ขั้นตอนถัดไป
- ลองใช้การเชื่อมต่อแหล่งข้อมูลกับ Google Search ใน Gemini API สูตรการแก้ปัญหา
- ดูข้อมูลเกี่ยวกับเครื่องมืออื่นๆ ที่มี
- ดูข้อมูลเพิ่มเติมเกี่ยวกับแนวทางปฏิบัติแนะนำด้าน AI ที่มีความรับผิดชอบและตัวกรองความปลอดภัยของ Gemini API ได้ในคู่มือการตั้งค่าความปลอดภัย