我正在制作一个React Native应用程序,该应用程序需要使用Google PlacesSuggestion作为react native。所以我用了一个包装:
react-native-google-places-autocomplete
这是代码:
<View style = {{margin:10,padding:20,flex:1}}>
<GooglePlacesAutocomplete
placeholder='Search'
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
// ToastAndroid.show(JSON.stringify(data),ToastAndroid.LONG)
let city = details.address_components[0].long_name
let lat = details.geometry.location.lat
let lng = details.geometry.location.lng
let full_addr= details.formatted_address
}}
getDefaultValue={() => ''}
query={{
key: 'AIzaSyB-q60XaNf5nsz5678e1jaRg0KTs5Q1nPi2Zk',
language: 'en', // language of the results
types: 'geocode' // default: 'geocode'
}}
styles={{
textInputContainer: {
width: '100%'
},
description: {
fontWeight: 'bold'
}
}}
nearbyPlacesAPI='GooglePlacesSearch' // Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
GoogleReverseGeocodingQuery={{
}}
GooglePlacesSearchQuery={{
rankby: 'distance',
types: 'food'
}}
filterReverseGeocodingByTypes={[ 'political','administrative_area_level_3']} // filter the reverse geocoding results by types - ['locality', 'administrative_area_level_3'] if you want to display only cities
debounce={200} // debounce the requests in ms. Set to 0 to remove debounce. By default 0ms.
/>
</View>
但是上面的代码出现了两个问题。输入任何位置时,我的响应都非常缓慢,我的意思是,输入位置的字符或单词后,需要2-3秒才能显示结果,有时却不显示任何结果,为什么?另外,如果我想根据道路名称和区域名称搜索地址,那么它也不会给我任何建议。为什么?我被这两个问题困扰,请在这两个问题上帮助我。预先感谢