繁体   English   中英

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

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

我在我的应用程序中使用 react-native-google-places-autocomplete package。 有两个字段使用此 package:- 当前位置和目的地。 在我输入位置并使用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',
                  },
             }}
    />

以下代码正是我用于“当前位置”字段的代码。 但是为什么当它们是完全相同的副本时我会得到这个 typeError 呢? 唯一的区别是目的地纬度和目的地经度参数。

哦,我现在找到原因了。 这是因为我没有将fetchDetails设置为 true。 傻我

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM