问题描述
我正在使用react-native-google-places-autocomplete获取基于用户当前位置的位置建议。它工作正常,但是我面临的唯一问题是,每当单击“当前位置”按钮时,它都会将输入字段设置为值“当前位置”,然后以其下方列表的形式显示位置结果。
我不希望它在输入字段中设置currentLocationLabel
的值。
import React from 'react';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';
navigator.geolocation = require('@react-native-community/geolocation');
const LocationAutocompleteScreen = props => {
return (
<GooglePlacesAutocomplete
placeholder='Search Location...'
minLength={3}
autoFocus={true}
returnKeyType={'search'}
listViewDisplayed='auto'
fetchDetails={true}
onPress={(data,details = null) => {
const locParam = {
description: data.description,placeId: data.place_id,location: details.geometry.location
}
props.navigation.navigate('LocationSearch',{locParam} )
}}
getDefaultValue={() => {
return '' // text input default value
}}
query={{
key: 'API_KEY',language: 'en',components: 'country:in',}}
styles={{
textInputContainer: {
backgroundColor: '#fff',borderTopWidth: 0,borderBottomWidth: 0,marginTop: 16,marginHorizontal: 16
},textInput: {
marginLeft: 0,marginRight: 0,padding: 8,minHeight: 30,color: '#000000',fontSize: 16,fontWeight: 'bold'
},predefinedPlacesDescription: {
color: '#1faadb',},listView: {
paddingHorizontal: 8
},description: {
fontWeight: '700',letterSpacing: 0.5,color: '#5d5d5d'
}
}}
currentLocation={true}
currentLocationLabel='Current Location'
nearbyPlacesAPI='GoogleReverseGeocoding' // Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
//renderDescription={row => row.description || row.formatted_address || row.name}
// 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: 'food'
// }}
//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
/>
);
}
export default LocationAutocompleteScreen;
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)