【发布时间】:2020-01-28 11:03:15
【问题描述】:
react-native-google-places-autocomplete 不起作用,我面临多个问题 1.places drop down 没有出现 2. onPress 处理程序根本没有被触发
注意:所有 google location api 都已启用,google maps api、places api 和 geocode api 都已启用,并提供了有效的 api 密钥。
我尝试了互联网上所有可能的解决方案 1. 设置 zIndex: 1000 一个高值以避免它被隐藏在其他视图后面 2.尝试创建新的RN App并仅添加此组件以保持项目清洁 3. 推荐其他SO post and tried to fix it
这里是代码 sn-p
<GooglePlacesAutocomplete
placeholder="Search"
minLength={2} // minimum length of text to search
autoFocus={false}
fetchDetails={true}
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
console.log(data);
console.log(details);
}}
getDefaultValue={() => {
return ''; // text input default value
}}
query={{
// available options: https://developers.google.com/places/web-service/autocomplete
key: 'VALID_API_KEY',
language: 'en', // language of the results
}}
styles={{
description: {
fontWeight: 'bold',
},
predefinedPlacesDescription: {
color: '#1faadb',
},
listView: {
color: 'black', //To see where exactly the list is
zIndex: 1000, //To popover the component outwards
position: 'absolute',
top: 45
},
}}
currentLocation={true} // Will add a 'Current location' button at the top of the predefined places list
currentLocationLabel="Current location"
nearbyPlacesAPI="GooglePlacesSearch" // Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
GoogleReverseGeocodingQuery={
{
// available options for GoogleReverseGeocoding API : https://developers.google.com/maps/documentation/geocoding/intro
}
}
GooglePlacesDetailsQuery={{
// available options for GooglePlacesDetails API : https://developers.google.com/places/web-service/details
fields: 'formatted_address',
}}
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]}
predefinedPlacesAlwaysVisible={true}
/>
【问题讨论】:
-
嗨@Sadand,你能解决这个问题吗?如果你能解决它,你能分享一下你做了什么吗?
-
@AhmadAli 还没有,我还在探索中。
-
你找到解决办法了吗?
-
@mendy 仍然没有...
标签: react-native react-native-android