是否可以控制Google商家信息自动填充SearchBox服务预测?

时间:2018-02-20 14:00:22

标签: javascript reactjs google-maps react-redux

是否可以控制(启用/停用)Google商家信息自动填充SearchBox(google.maps.places.SearchBox)服务预测?用户输入3个字符后需要自动填充

这是我的搜索框:

<input id='mapLocation' onChange={this.autoComplete.bind(this)} type='text' placeholder='' ref='search_location' required autofocus />

这是我的自动填充方法:

autoComplete() {
        let that = this;
        let google = window.google;
        google.maps.event.addListener(this.state.AutoCompleteSdk, 'places_changed', function () {
            if (!that.stopPropagation_) {
                let places = that.state.AutoCompleteSdk.getPlaces();
                _.map(places, (place) => {
                    let marker = new google.maps.Marker({
                        isChecked: true,
                        position: { lat: place.geometry.location.lat(), lng: place.geometry.location.lng() },
                        icon: markerIcon
                    });
                    marker.bindTo('map', that.state.AutoCompleteSdk, 'map');
                    that.state.listOfmarks.push(marker);
                    that.state.selectedPlaces.push({ formatted_address: place.formatted_address, isChecked: true, place: place });
                })
                that.stopPropagation_ = true;
                that.setState({}, () => that.resetMarker());
            }
        });
    }

并且状态AutoCompleteSdk是:

let AutoCompleteSdk = new google.maps.places.SearchBox(document.getElementById('mapLocation'));

我试过AutoCompleteSdk.unbindAll();但它不起作用。请给我一个建议如何关闭前3个字符的自动完成。在我需要开始之后

0 个答案:

没有答案