就近宾馆查询附近酒店
请输入您的位置:
javascript const form = document.querySelector("form"); const locationInput = document.querySelector("location"); const results = document.querySelector("results");form.addEventListener("submit", (e) => {e.preventDefault();const location = locationInput.value;// 使用地理编码服务将位置转换为经纬度const geocoder = new google.maps.Geocoder();geocoder.geocode({ address: location }, (results, status) => {if (status === "OK") {const lat = results[0].geometry.location.lat();const lng = results[0].geometry.location.lng();// 使用酒店搜索服务查询附近酒店const hotelSearchService = new google.maps.places.PlacesService(results);const request = {location: new google.maps.LatLng(lat, lng),radius: 500, // 以米为单位的搜索半径type: "hotel",};hotelSearchService.nearbySearch(request, (nearbyHotels, status) => {if (status === "OK") {// 清空之前的搜索结果results.innerHTML = "";// 显示搜索结果nearbyHotels.forEach((hotel) => {const name = hotel.name;const address = hotel.vicinity;const li = document.createElement("li");li.innerHTML = `${name} - ${address}`;results.appendChild(li);});} else {alert("出错了!请重试。");}});} else {alert("找不到该位置!请重试。");}}); });
郑重声明:部分文章来源于网络,仅作为参考,如果网站中图片和文字侵犯了您的版权,请联系我们处理!
相关推荐
旅游攻略
景区攻略
国外旅游攻略
旅游团
旅游推荐
成都民宿
攻略首页