简体   繁体   English

类型错误:未定义不是 object(正在评估“details.geometry.location”)

[英]TypeError: undefined is not an object (evaluating 'details.geometry.location')

I'm using react-native-google-places-autocomplete package in my app.我在我的应用程序中使用 react-native-google-places-autocomplete package。 There are two fields that uses this package:- Current Location and Destination.有两个字段使用此 package:- 当前位置和目的地。 Current Location works perfectly fine without error after i entered the location and set the value of lat/lng using details.geometry.location .在我输入位置并使用details.geometry.location设置 lat/lng 的值后,当前位置工作得很好,没有错误。 However, the typeError only occurs after i set the Destination location.但是,typeError 仅在我设置目标位置后发生。 Below is my code.下面是我的代码。

    <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',
                  },
             }}
    />

The following code is exactly what I use for the Current Location field.以下代码正是我用于“当前位置”字段的代码。 But why am I getting this typeError when they're exactly the same copy?但是为什么当它们是完全相同的副本时我会得到这个 typeError 呢? The only difference are destinationlatitude and destinationlongitude parameters.唯一的区别是目的地纬度和目的地经度参数。

Oh I found the cause now.哦,我现在找到原因了。 It's because I didn't set the fetchDetails to true.这是因为我没有将fetchDetails设置为 true。 Silly me傻我

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:未定义不是对象(评估“this._callListeners.bind”) - TypeError: undefined is not an object (evaluating 'this._callListeners.bind') 映射函数 - 未处理的 JS 异常:TypeError:undefined 不是评估映射的对象 - Map Function - Unhandled JS Exception: TypeError: undefined is not an object evaluating map TypeError: undefined is not an object (evalating &#39;icons.map&#39;) React-Native - TypeError: undefined is not an object (evaluating 'icons.map') React-Native TypeError: undefined is not an object(评估'_ExponentFacebook.default.initializeAsync') - TypeError: undefined is not an object (evaluating '_ExponentFacebook.default.initializeAsync') 使用 expo-image-picker 时出错:TypeError: undefined is not an object(评估 '_expoModulesCore.NativeModulesProxy.ExponentImagePicker') - error while using expo-image-picker:TypeError: undefined is not an object (evaluating '_expoModulesCore.NativeModulesProxy.ExponentImagePicker') TypeError: undefined is not an object (评估'_$$_REQUIRE(_dependencyMap[32], "react-native-safe-area-context").SafeAreaView') - TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[32], "react-native-safe-area-context").SafeAreaView') 错误类型错误:无法读取未定义的属性“详细信息” - ERROR TypeError: Cannot read property 'details' of undefined TypeError:未定义不是对象(TS) - TypeError: undefined is not an object (TS) undefined 不是 object(评估“item.Attraction.Name”) - undefined is not an object (evaluating 'item.Attraction.Name') TypeError: undefined is not a constructor (评估 &#39;this.service.getDat().subscribe&#39;) - TypeError: undefined is not a constructor (evaluating 'this.service.getDat().subscribe')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM