就近汽车修理厂位置 (就近汽车修理店)

成都洗浴 04-10 阅读:53 评论:0
就近汽车修理厂位置 (就近汽车修理店)

快速轻松地找到您附近的汽车修理店。

Copyright © 2023 就近汽车修理厂位置

javascript // script.js const API_KEY = "YOUR_API_KEY"; const map = new google.maps.Map(document.getElementById("map-container"), {zoom: 12,center: { lat: -33.8688, lng: 151.2093 }, });const repairShops = [];const searchForm = document.getElementById("search"); searchForm.addEventListener("submit", (event) => {event.preventDefault();const location = document.getElementById("location").value;const request= {query: "汽车修理厂",location: location,radius: 5000,};const service = new google.maps.places.PlacesService(map);service.textSearch(request, (results, status) => {if (status === google.maps.places.PlacesServiceStatus.OK) {clearResults();displayResults(results);displayMarkers(results);} else {alert("抱歉,我们无法找到任何汽车修理店。");}}); });function displayResults(results) {const resultList = document.getElementById("repair-shops");results.forEach((result) => {const item = document.createElement("li");item.innerHTML = result.name;resultList.appendChild(item);}); }function displayMarkers(results) {results.forEach((result) => {const marker = new google.maps.Marker({position: result.geometry.location,map: map,title: result.name,});repairShops.push(marker);}); }function clearResults() {const resultList = document.getElementById("repair-shops");while (resultList.firstChild) {resultList.removeChild(resultList.firstChild);}repairShops.forEach((marker) => {marker.setMap(null);});repairShops.length = 0; }
版权声明

本文仅代表作者观点,不代表成都桑拿立场。
本文系作者授权发表,未经许可,不得转载。