谷歌地图搜索功能的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);
            });
相关推荐
java水泥工12 小时前
课程答疑系统|基于SpringBoot和Vue的课程答疑系统(源码+数据库+文档)
spring boot·vue·计算机毕业设计·java毕业设计·大学生毕业设计·课程答疑系统
阿洛学长1 天前
高质量 AI 提示词之(从 0-1 开发 Vue 项目)
vue·ai编程·1024程序员节
IT教程资源D1 天前
[N_149]基于微信小程序网上商城系统
mysql·vue·前后端分离·springboot网上商城·网上商城小程序
ytgytg281 天前
芋道源码:VUE3部署:避坑--验证码不现显示,管理后台无法访问后端接口等,完善中。。。
java·vue
小林up1 天前
【bug解决】[string “tolua.lua“]:1: ‘=‘ expected
bug·lua
学会煎墙2 天前
使用uniapp——实现微信小程序的拖拽排序(vue3+ts)
微信小程序·uni-app·vue·ts
神膘护体小月半2 天前
bug 记录 - 路由守卫 beforeRouteLeave 与 confirm 结合,不生效问题
javascript·vue
江拥羡橙2 天前
css实现拼图样式,响应不同屏幕宽度
vue·less·css3·html5·1024程序员节·calc
凌晨一点的秃头猪3 天前
Python 常见 bug 总结和异常处理
开发语言·python·bug
惜.己3 天前
从零使用vue脚手架开发一个简易的计算器
vue·js·1024程序员节