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

我想找附近住宿的地方 (我想找附近住的地方)

2024-10-18 11:59分类: 成都旅游 阅读:

 

你想找附近住的地方?使用我们的地图,轻松找到适合你的住宿场所。

<script> // 初始化地图const map = new google.maps.Map(document.querySelector('.map'), {center: { lat: -34.397, lng: 150.644 },zoom: 12,});// 创建信息窗口const infoWindow = new google.maps.InfoWindow();// 获取用户位置if (navigator.geolocation) {navigator.geolocation.getCurrentPosition(position => {const userLatLng = { lat: position.coords.latitude, lng: position.coords.longitude };map.setCenter(userLatLng);});}// 搜索附近的住宿const request = {location: map.getCenter(),radius: 500,type: 'lodging',};const service = new google.maps.places.PlacesService(map);service.nearbySearch(request, (results, status) => {if (status === google.maps.places.PlacesServiceStatus.OK) {results.forEach(result => {// 创建标记const marker = new google.maps.Marker({position: result.geometry.location,map: map,});// 添加信息窗口事件监听器marker.addListener('click', () => {infoWindow.setContent(result.name);infoWindow.open(map, marker);});// 创建结果列表项const li = document.createElement('li');li.innerHTML = `${result.name}

${result.vicinity}

`;// 添加结果列表项到列表中document.querySelector('results').appendChild(li);});}});


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

上一篇:客栈民宿预定 (客栈民宿预定app)

下一篇:客栈民宿排行榜 (客栈民宿排行前十)

附近酒店推荐

关注我们

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