Google Maps Place API 和 Google Maps Time Zone API 是 Google Maps 平台提供的两个不同功能的接口,它们在用途、数据返回类型和应用场景上有显著区别。以下是详细对比:
| 维度 | Place API | Time Zone API | |----------------|---------------------------------------|---------------------------------------| | 数据目标 | 地点详细信息(名称、地址、评分等) | 时区信息(UTC偏移、时区ID等) | | 输入参数 | 文本关键词或经纬度 | 经纬度 + 时间戳(可选) | | 返回字段 | 结构化地点数据(JSON/XML) | 时区偏移、夏令时状态等 | | 典型场景 | 本地服务搜索、导航应用、旅游推荐 | 跨时区会议调度、日志时间标准化 |
// 使用 Google Maps Places API 搜索“纽约中央公园”
const apiKey = 'YOUR_API_KEY';
const url = `https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Central%20Park&inputtype=textquery&fields=name,formatted_address,rating&key=${apiKey}`;
fetch(url)
.then(response => response.json())
.then(data => console.log(data));
// 根据经纬度获取时区(纽约坐标)
const apiKey = 'YOUR_API_KEY';
const timestamp = Math.floor(Date.now() / 1000); // 当前时间戳
const url = `https://maps.googleapis.com/maps/api/timezone/json?location=40.7128,-74.0060×tamp=${timestamp}&key=${apiKey}`;
fetch(url)
.then(response => response.json())
.then(data => console.log(data.timeZoneId)); // 输出示例:"America/New_York"
两者可结合使用(例如:先用 Place API 获取坐标,再通过 Time Zone API 计算当地时间)。
没有搜到相关的文章