Google Places API 是 Google 提供的一套服务接口,允许开发者访问 Google 庞大的地点数据库,获取各种地点信息,包括名称、地址、营业时间、评价等。
是的,Google Places API 可以在不提供具体位置的情况下查询特定类型的地点(如学校),但有一定限制:
问题1:返回结果不相关或质量差
问题2:结果数量不足
问题3:API返回错误
// 使用Text Search API查询学校
async function searchSchools() {
const apiKey = 'YOUR_API_KEY';
const url = `https://maps.googleapis.com/maps/api/place/textsearch/json?query=school&type=school&key=${apiKey}`;
try {
const response = await fetch(url);
const data = await response.json();
if (data.status === 'OK') {
console.log('找到的学校:', data.results);
} else {
console.error('API错误:', data.status);
}
} catch (error) {
console.error('请求失败:', error);
}
}
searchSchools();
没有搜到相关的文章