如果您已有 Place 对象或地点 ID,则可以调用 Place.fetchFields 获取有关该地点的更多详情。您可以使用 fields 参数指定一个逗号分隔列表,其中包含一个或多个采用驼峰命名法的地点数据字段。使用返回的 Place 对象获取所请求字段的数据。
以下示例使用地点 ID 创建新的 Place,调用请求 displayName 和 formattedAddress 字段的 Place.fetchFields,然后将生成的数据记录到控制台。
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);
}