【发布时间】:2018-06-09 21:39:49
【问题描述】:
我开发了一个后端 API,它给出了一个位置的纬度和经度,它使用 Google Places Photos API 返回城市的图像
我的 React Native 应用程序调用端点来尝试将图像加载到 Image 视图中。这就是应用调用端点并接收响应的方式...
try {
let imageResponse = await fetch(
`https://budgettrip.herokuapp.com/locationimage/${latitude}/${longitude}`
);
let response = await imageResponse;
this.setState({ locationImage: response });
} catch (error) {
console.error('location image error', error);
}
用于从 Google 获取图像并将响应发送回我的 React Native 应用程序的后端代码...
var locationimage = {
uri: `https://maps.googleapis.com/maps/api/place/photo?photoreference=${photo_reference}&sensor=false&maxheight=1600&maxwidth=1600&key=${process.env.GOOGLE_PLACES_API_KEY}`,
headers: {
'User-Agent': 'Request-Promise'
}
};
rp(locationimage)
.then(function(repos) {
res.send(repos);
})
.catch(function(err) {
// API call failed...
res.send(JSON.stringify({ error: 'Could not get image' }));
})
您可以尝试端点以查看成功时的响应here
我不确定如何在 Image 视图中显示来自响应的图像,因为响应不是带有 url 或本地文件的网络图像。
【问题讨论】:
标签: javascript react-native google-places-api google-places