Google Directions API 是 Google Maps Platform 提供的服务之一,用于获取两点或多点之间的路线规划信息。以下是关于其查询限制的详细说明:
Google Directions API 允许开发者通过 HTTP 请求获取以下数据:
waypoints
参数一次性获取多点的路线(最多 25 个)。// 示例:处理 API 限流的重试逻辑(JavaScript)
async function getRoute(origin, destination) {
try {
const response = await fetch(`https://maps.googleapis.com/maps/api/directions/json?origin=${origin}&destination=${destination}&key=YOUR_API_KEY`);
const data = await response.json();
if (data.status === "OVER_QUERY_LIMIT") {
console.log("触发限流,1秒后重试...");
await new Promise(resolve => setTimeout(resolve, 1000));
return getRoute(origin, destination); // 递归重试
}
return data;
} catch (error) {
console.error("请求失败:", error);
}
}
REQUEST_DENIED
?如需进一步扩展配额或功能,建议参考 Google Maps Platform 官方文档。
没有搜到相关的文章