我正在构建一个API终结点,该终结点将使用express.js和Node.js客户端库(用于Google Maps API Web服务)返回详细信息和一张Google地方的照片。下面的端点返回一个地点的详细信息,我在检索照片的URL时遇到了麻烦。下面是有问题的代码。
对Google Maps客户端有两个请求:
req.params.id并且详细信息包含一个photos数组photo_reference从上方获取照片
var googleMapsClient = require('@google/maps').createClient({
key: 'mykeyhere',
Promise: Promise
});
exports.getGglPlace = function(req, res) {
googleMapsClient.place({
placeid: req.params.id
}).asPromise()
.then((response) => {
var venue = response.json.result
if (venue.photos[0]) {
googleMapsClient.placesPhoto({
photoreference: venue.photos[0].photo_reference,
maxwidth: 200
}).asPromise()
.then((photo) => {
console.log("Photo:", photo); // this returns a massive chunk of data which I think contains the actual image object also
venue.photoURL = photo.url; // this doesn't work
res.send(venue);
}) …Run Code Online (Sandbox Code Playgroud)