输入您的位置,找到附近的住宿旅馆:
<script> const locationInput = document.getElementById('location');const resultsDiv = document.getElementById('results');// 事件监听器,在提交表单后触发locationInput.addEventListener('submit', (event) => {event.preventDefault();// 获取输入位置const location = locationInput.value;// 使用地理编码服务将位置转换为经纬度const geocoder = new google.maps.Geocoder();geocoder.geocode({ address: location }, (results, status) => {if (status === google.maps.GeocoderStatus.OK) {// 成功获取经纬度const lat = results[0].geometry.location.lat();const lng = results[0].geometry.location.lng();// 使用经纬度查找附近的住宿旅馆const request = {location: new google.maps.LatLng(lat, lng),radius: 5000, // 5公里半径type: 'lodging',};const service = new google.maps.places.PlacesService(retelLink.textContent = '查看详细信息';li.appendChild(hotelLink);// 将列表项目添加到结果中resultsDiv.appendChild(li);});} else {// 查找住宿旅馆失败resultsDiv.textContent = '抱歉,找不到任何住宿旅馆。';}});} else {// 无法获取经纬度resultsDiv.textContent = '抱歉,无法找到该位置。';}});}); script>