如果您已經有 Place 物件或地點 ID,可以呼叫 Place.fetchFields 取得該地點的詳細資料。您可以使用 fields 參數指定一份以半形逗號分隔的清單,其中包含一或多個採用駝峰式大小寫的地點資料欄位。使用傳回的 Place 物件,即可取得所要求欄位的資料。
下例使用地點 ID 建立新的 Place,並呼叫 Place.fetchFields 來要求 displayName 和 formattedAddress 欄位,然後將產生的資料記錄到控制台。
TypeScript
async function getPlaceDetails(Place) {
// Use place ID to create a new Place instance.
const place = new Place({
id: 'ChIJN1t_tDeuEmsRUsoyG83frY4',
requestedLanguage: 'en', // optional
});
// Call fetchFields, passing the desired data fields.
await place.fetchFields({ fields: ['displayName', 'formattedAddress'] });
// Show the result
console.log(place.displayName);
console.log(place.formattedAddress);
}
async function getPlaceDetails(Place) {
// Use place ID to create a new Place instance.
const place = new Place({
id: "ChIJN1t_tDeuEmsRUsoyG83frY4",
requestedLanguage: "en", // optional
});
// Call fetchFields, passing the desired data fields.
await place.fetchFields({ fields: ["displayName", "formattedAddress"] });
// Show the result
console.log(place.displayName);
console.log(place.formattedAddress);
}