当前位置: 民宿 > 成都旅游

附近酒店查询附近酒店 (附近酒店查询500米内)

2024-10-18 15:37分类: 成都旅游 阅读:

 

请输入您的位置,我们将在 500 米范围内为您查找酒店




<script> function initMap() {// 创建地图对象const map = new google.maps.Map(document.getElementById("map"), {center: { lat: -34.397, lng: 150.644 },zoom: 15,});// 创建信息窗口对象const infowindow = new google.maps.InfoWindow();// 获取表单数据const form = document.querySelector("form");form.addEventListener("submit", (e) => {e.preventDefault();const latitude = document.getElementById("latitude").value;const longitude = document.getElementById("longitude").value;// 创建位置对象const location = new google.maps.LatLng(latitude, longitude);// 在地图上设置中心点map.setCenter(location);// 在位置上放置标记const marker = new google.maps.Marker({position: location,map: map,});// 在标记上添加事件监听器,以显示信息窗口marker.addListener("click", () => { infowindow.setContent(`这是您的位置:${latitude}, ${longitude}`);infowindow.open(map, marker);});// 搜索 500 米半径范围内的酒店const request = {location: location,radius: 500,type: "hotel",};const service = new google.maps.places.PlacesService(map);service.nearbySearch(request, (results, status) => {if (status === google.maps.places.PlacesServiceStatus.OK) {// 清除之前的结果map.markers.forEach((marker) => marker.setMap(null));// 在地图上绘制结果for (let i = 0; i < results.length; i++) {const place = results[i];const marker = new google.maps.Marker({position: place.geometry.location,map: map,});// 在标记上添加事件监听器,以显示信息窗口marker.addListener("click", () => {infowindow.setContent(`这是 ${place.name},评分为 ${place.rating}`);infowindow.open(map, marker);});}}});});}window.onload = initMap;


郑重声明:本文由:成都旅游于(2024-10-18)发表了关于附近酒店查询附近酒店 (附近酒店查询500米内)的文章。如转载请注明出处!部分文章来源于网络,仅作为参考,如果网站中图片和文字侵犯了您的版权,请联系我们处理!

上一篇:附近的大酒店住宿查询 (附近的大酒店有哪些?)

下一篇:附近的酒店住宿查询 (附近的酒店住宿查询价格)

附近酒店推荐

关注我们

    民宿酒店不一样的选择,更好的体验