问题描述
我在我的应用中使用 react-native-google-places-autocomplete 包。有两个字段使用此包:- 当前位置和目的地。在我输入位置并使用 details.geometry.location
设置 lat/lng 的值后,当前位置工作完美无误。但是,typeError 仅在我设置目标位置后发生。下面是我的代码。
<GooglePlacesAutocomplete
placeholder=""
query={{
key: GOOGLE_PLACES_API_KEY,language: 'en',// language of the results
}}
onPress={(data,details:any) => { setDestinationLatitude(details.geometry.location.lat.toString()); setDestinationLongitude(details.geometry.location.lng.toString()); }}
onFail={(error) => console.error(error)}
requestUrl={{
url:
'https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api',uSEOnPlatform: 'web',}} // this in only required for use on the web. See https://git.io/JflFv more for details.
keyboardShouldPersistTaps='always'
styles={{
textInputContainer: {
width: "90%",//top: 8,alignSelf: 'center'
},textInput: {
borderColor: grey,borderWidth: 1,borderRadius: 5,height: 48,paddingBottom: 8,color: black,fontSize: 16,},predefinedplacesDescription: {
color: '#1faadb',}}
/>
以下代码正是我用于当前位置字段的代码。但是,当它们完全相同时,为什么我会收到此类型错误?唯一的区别是destinationlatitude 和destinationlongitude 参数。
解决方法
哦,我现在找到原因了。这是因为我没有将 fetchDetails
设置为 true。傻我