首页 > 解决方案 > Google API - 在 React Native Expo 项目中放置自动完成功能

问题描述

我正在使用 React Native Expo开发移动应用程序。我正在使用react-native-google-places-autocomplete文本自动完成位置/地点。它是谷歌 API。我已经创建了帐户,启用了谷歌服务并添加了我的账单信息。但代码不起作用。

请看下面的代码:

        <View style={{height: 500}}>
        <GooglePlacesAutocomplete

        fetchDetails={true}
        placeholder='Search'
        onPress={(data, details = null) => {
            console.log(data, details);
        }}
        query={{
            key: 'my-api-key-here',
            language: 'en',
        }}
        />
        </View>

我能够成功地看到Search我可以输入的占位符,但我无法看到谷歌的建议/自动完成文本。我可以在框中成功输入位置,但谷歌没有提供位置建议。

我也安装并导入了相关库。

标签: reactjsreact-nativegoogle-apiexpogoogleplacesautocomplete

解决方案


您需要添加道具 listViewDisplayed={boolean or "auto"}。请参阅此链接https://snack.expo.io/@tobzy/react-native-google-places-autocomplete-example


推荐阅读