谷歌地图搜索功能的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);
            });
相关推荐
IT教程资源C4 小时前
(N_122)基于springboot,vue网上订餐系统
mysql·vue·前后端分离·网上订餐系统·springboot网上订餐
测试19985 小时前
一个只能通过压测发现Bug
自动化测试·软件测试·python·selenium·测试工具·bug·压力测试
星光一影7 小时前
美容/心理咨询/问诊/法律咨询/牙医预约/线上线下预约/牙医行业通用医疗预约咨询小程序
mysql·小程序·vue·php·uniapp
yuyu_03047 小时前
SOHE智能厨余垃圾处理系统
java·vue
狂奔的sherry10 小时前
网卡获取模组ip失败问题解析
bug
Watermelo61711 小时前
【前端实战】从 try-catch 回调到链式调用:一种更优雅的 async/await 错误处理方案
前端·javascript·网络·vue.js·算法·vue·用户体验
狼性书生11 小时前
uniapp实现的时间范围选择器组件
前端·uni-app·vue·组件·插件
Irene19911 天前
CLI 与 Vite 创建项目对比(附:最优解 create-vue)
vue·vite·cli·项目创建
nnsix1 天前
Unity ReferenceFinder插件 多选资源查找bug解决
unity·游戏引擎·bug
中冕—霍格沃兹软件开发测试1 天前
边界值分析:功能测试中的精度利器
人工智能·功能测试·科技·测试工具·appium·bug