首页 > 解决方案 > 已选择位置时如何在 GooglePlacesAutocomplete 中停止自动完成搜索?

问题描述

我正在使用 react-native-google-places-autocomplete。当用户键入位置时,会出现搜索选项,然后用户可以选择位置。

但是,在用户按下并选择了一个位置后,搜索选项仍然会出现。

如何确保用户选择位置后搜索选项消失。

下面是我的组件:

   <GooglePlacesAutocomplete
              placeholder='Business Location'
              minLength={2} // minimum length of text to search
              autoFocus={false}
              returnKeyType={'search'} // Can be left out for default return key https://facebook.github.io/react-native/docs/textinput.html#returnkeytype
              listViewDisplayed='auto'    // true/false/undefined
              fetchDetails={true}
              renderDescription={row => row.description} // custom description render
              onPress={(data, details = null) => { // 'details' is provided when fetchDetails = true
                this.setState({ location: data.description });
                this.validateLocation();
              }}
              getDefaultValue={() => ''}
              query={{
                // available options: https://developers.google.com/places/web-service/autocomplete
                key: 'XXXXXXXXXXXXXXXXXXXXXXXX',
                language: 'en', // language of the results
                types: 'geocode' // default: 'geocode'
              }}
              styles={{
                                textInputContainer: {
                                 backgroundColor: 'white',
                                  width: 0.8*width,
                                  marginLeft: 0.1*width,
                                  height: 0.1*height,
                                   zIndex: 1,
                                  borderTopWidth: 0,
                                  borderBottomWidth: 1,
                                  borderColor: 'black'

                                }
                              }}
              //currentLocation={true} // Will add a 'Current location' button at the top of the predefined places list
              nearbyPlacesAPI='GooglePlacesSearch' // Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
              GoogleReverseGeocodingQuery={{
                // available options for GoogleReverseGeocoding API : https://developers.google.com/maps/documentation/geocoding/intro
              }}
              GooglePlacesSearchQuery={{
                // available options for GooglePlacesSearch API : https://developers.google.com/places/web-service/search
                rankby: 'distance',
                types: ''
              }}
              filterReverseGeocodingByTypes={['locality', 'administrative_area_level_3']} // filter the reverse geocoding results by types - ['locality', 'administrative_area_level_3'] if you want to display only cities
              predefinedPlaces={[//homePlace, workPlace
              ]}
              debounce={200} // debounce the requests in ms. Set to 0 to remove debounce. By default 0ms.
              value={this.state.location}
              onChangeText={(location) => {
                this.setState({ location });
                this.validateLocation();
              }}
              //renderLeftButton={()  => <Icon name="map-marker" size={28} color="#000" style={{ marginTop: 0.015*width }} />}
              //renderRightButton={() => <Icon name="rocket" size={30} color="#900" />}
           />

标签: react-nativegoogleplacesautocomplete

解决方案


推荐阅读