【问题标题】:Possibility of loading Google places images in react-native Image component?加载 Google 的可能性会将图像放置在 react-native Image 组件中吗?
【发布时间】:2018-02-16 10:22:58
【问题描述】:

我正在尝试使用如下所示的 react-native 的 Image 组件,将我从地点 api 获得的图像参考加载到地点照片 API 中,

const imageLink = 'https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CmRaAAAAuZ36wzrMYCVNWM1smQkRKuQyXecPgRpcsMfrSqbJM0EUTXZ62j8Ljxtk8HsxohXbtAwZAwmj_F3HmDwLoQaH9qt2TZJhhA6EuXK41UFo0Ow750MJujtrr5hgHR2lF7EXEhCkWj_dZ4LefrYzLU1_5RF1GhTR7Ggem5IJ-v7V2U8fjKoU9tBUOg&key=--MyKey--'
return (
        <View >
            <TouchableHighlight >
                    <View>
                        <Image
                            style={{width:64, height:64,flex:1,backgroundColor:'red'}}
                            source={{uri: imageLink}}
                        />


                    </View>    
             </TouchableHighlight>
        </View>

    );

我只得到了上面代码的空占位符。但是,我可以在浏览器中加载此链接。需要注意的是,谷歌将照片的链接重定向到其他一些 url,然后在浏览器中显示图像。我做对了吗?或者有没有其他方法我可以做到这一点。注意:我也试过 react-native-network-image 库。

【问题讨论】:

  • 您好,您找到任何解决方案了吗。我也面临同样的问题,如果有任何解决方案,请告诉我

标签: react-native react-native-android react-native-image


【解决方案1】:

你可以看看 googleplace 模块中的 ImagePrefetch 函数: https://github.com/srirangan/googleplaces.js/blob/master/test/ImageFetchTest.js

但是,由于在此特定函数中调用了 var https = require("https"); 行,我目前对整个模块有疑问。 不确定这是新版本的 RN(最近升级到 0.55)的问题,还是我的新设置中的其他错误。

这在以前的 RN 中完美运行(在 0.48 上运行)

【讨论】:

    猜你喜欢
    • 2015-12-24
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    • 2020-11-24
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多