Google Places API 是 Google 提供的一项服务,允许开发者访问 Google 的场所数据库,获取地点信息、搜索附近地点、获取地点详情等。
// 示例:调试 Google Places API 请求
async function testPlacesApi() {
const apiKey = 'YOUR_API_KEY';
const location = '40.7128,-74.0060'; // 纽约坐标
const radius = 500; // 500米半径
const type = 'restaurant';
const url = `https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${location}&radius=${radius}&type=${type}&key=${apiKey}`;
try {
const response = await fetch(url);
const data = await response.json();
if (data.status === 'OK') {
console.log('API 返回结果:', data.results);
} else {
console.error('API 返回错误:', data.status, data.error_message || '');
}
} catch (error) {
console.error('请求失败:', error);
}
}
testPlacesApi();
INVALID_REQUEST
- 请求参数缺失或无效REQUEST_DENIED
- API 密钥无效或未启用服务OVER_QUERY_LIMIT
- 超出配额限制UNKNOWN_ERROR
- 服务器端错误,通常需要重试ZERO_RESULTS
- 查询区域没有匹配结果如果问题仍然存在,建议检查 Google Cloud Console 的 API 仪表板获取更详细的错误信息和使用统计。