谷歌地图搜索功能的bug

1、当页面结构复杂,具体原因不知道,主要会导致pac-container 搜索列表容器跑到body,不会显示在input下,解决方案有一个:手动强制修改

html 复制代码
<div class="map_container" style="height:100%;">
        <div class="input_box">
            <input id="searchInput" ref="searchInput" v-model="searchKey" type="text" />
        </div>
        <div id="gmap" ref="gmap" style="height:100%;"></div>
        <div id="infowindow-content">
            <span id="place-name" class="title"></span><br />
            <span id="place-address"></span>
        </div>
    </div>
javascript 复制代码
 mounted () {
        var addressInputElement = document.querySelector('#searchInput');
        addressInputElement.addEventListener('focus', function () {
            var pacContainer = document.querySelector('.pac-container');
            addressInputElement.parentNode.appendChild(pacContainer);
        });
     }
css 复制代码
//scss语法
::v-deep .pac-container {  
  z-index: 9999999 !important;  
  top: 30px !important;  
  left: 0 !important; 
}

以下是谷歌地图的搜索功能的js代码

javascript 复制代码
          const mapDiv = document.getElementById('gmap');
          const map = new google.maps.Map(mapDiv, option);
          let options = {
                fields: ['ALL'],//搜索类型 :"formatted_address", "geometry", "name" 
                strictBounds: false,//严格模式
            };
            const input = document.getElementById('searchInput');
            console.log(input, 'this.optioninputinput');
            const autocomplete = new google.maps.places.Autocomplete(input, options);
            console.log(autocomplete, ' this.autocomplete');
            autocomplete.bindTo("bounds", map);

            //设置搜索地址功能
            const infowindow = new google.maps.InfoWindow();
            const infowindowContent = document.getElementById('infowindow-content');
            infowindow.setContent(infowindowContent);
            const marker = new google.maps.Marker({
                map: map,
                anchorPoint: new google.maps.Point(0, -29),
            });

            autocomplete.addListener("place_changed", () => {

                infowindow.close();
                marker.setVisible(false);
                const place = autocomplete.getPlace();
                console.log('触发搜索组件', place);

                if (!place.geometry || !place.geometry.location) {
                    window.alert("No details available for input: '" + place.name + "'");
                    return;
                }
                if (place.geometry.viewport) {
                    map.fitBounds(place.geometry.viewport);
                } else {
                    map.setCenter(place.geometry.location);
                    map.setZoom(17);
                }

                marker.setPosition(place.geometry.location);
                marker.setVisible(true);
                infowindowContent.children["place-name"].textContent = place.name;
                infowindowContent.children["place-address"].textContent = place.formatted_address;
                infowindow.open(map, marker);
            });
相关推荐
Ahtacca1 小时前
拒绝重复造轮子:利用自定义注解封装POI,实现Java通用Excel解析
java·javascript·vue·excel
Lz__Heng1 小时前
ESXI 6.7.0 update 2(VMware ESXi, 6.7.0, 13006603)监控采集数据已知BUG
bug·vmware
自学也学好编程1 小时前
【BUG】Claude Code跳过强制登录解决方法
bug
cat2bug1 天前
介绍一下Cat2Bug-App如何连接自己的Bug平台
bug
秋天枫叶351 天前
【k8s集群Docker + cri-dockerd】服务器重启或关机后 apiserver/controller/scheduler 无法自动恢复
linux·运维·服务器·容器·kubernetes·bug
IT教程资源1 天前
N-159基于springboot,vue,AI协同过滤算法旅游推荐系统
mysql·vue·前后端分离·springboot旅游推荐·协同过滤算法旅游推荐·ai旅游推荐
小趴菜不能喝2 天前
若依Plus 的XSSFilter 的bug
bug
wanzhong23332 天前
开发日记13-响应式变量
开发语言·前端·javascript·vue
wanzhong23332 天前
开发日记14-vite配置多环境
服务器·前端·vue
刘一说3 天前
Vue3 组合式 API(Composition API):逻辑复用的革命性实践
vue.js·vue