如果您正在寻找一家附近的修车厂,我们已经为您整理了一份清单。只需选择您所在的位置,我们就会为您提供该地区最好的修车厂列表。
按位置查找修车厂
js
const locationSelect = document.getElementById('location');
const searchButton = document.getElementById('search-button');
const resultsDiv = document.getElementById('results');searchButton.addEventListener('click', () => {const location = locationSelect.value;const url = `${location}&radius=5000&type=car_repair&key=YOUR_API_KEY`;fetch(url).then(response => response.json()).then(data => displayResults(data)).catch(error => console.error(error));
});function displayResults(data) {resultsDiv.innerHTML = '';const results = data.results;for (let i = 0; i < results.length; i++) {const result = results[i];const name = result.name;const address = result.vicinity;const lat = result.geometry.location.lat;const lng = result.geometry.location.lng;const div = document.createElement('div');div.innerHTML = `
${name}
${address}
获取路线
`;resultsDiv.appendChild(div);}
}