谷歌地图搜索功能的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);
            });
相关推荐
青主创享阁12 小时前
玄晶引擎2.7.8更新解析:全新UI+Sora接入,功能优化与Bug修复全汇总
人工智能·bug
在坚持一下我可没意见13 小时前
软件测试入门复习笔记:BUG篇
笔记·bug·测试
Zwj-c16 小时前
【测试报告】个人博客系统测试报告(功能测试、自动化测试、Bug描述)
功能测试·selenium·测试用例·bug
单车少年ing20 小时前
一个编码BUG
算法·bug
朱华飞Pro1 天前
vue2 精细级别判断图片页面
vue·页面优化
Zwj-c1 天前
【测试报告】学评一体化平台测试报告(功能测试、自动化测试、Bug描述)
python·功能测试·selenium·测试用例·bug
构建的乐趣1 天前
visual studio监视的有效方法【bug调试】
bug
维齐洛波奇特利(male)1 天前
IDEA 实例类多开bug:勾选后还是只能运行一个类
java·bug·intellij-idea
Luke Ewin1 天前
ASR数据集采集系统 | ASR方言数据集采集系统 | ASR方言数据集采集系统 | 语音识别数据集采集系统
vue·springboot·语音识别·asr·asr数据集采集·asr方言数据集采集
沙振宇1 天前
【Web】使用Vue3+PlayCanvas开发3D游戏(一)3D 立方体交互式游戏
游戏·3d·vue·vue3·playcanvas