简体   繁体   中英

Processing google photo reference to get the image url

I ham using node.js and have the photo reference string and want to get access to the image that is returned.

I have the following code and am getting back something in the body.

  locations.forEach(function(loc) {
    var photoRef;
    if (loc.photos && Array.isArray(loc.photos)) {

      photoRef = loc.photos[0].photo_reference;

      var url_in = 'https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=' + photoRef + '&key=' + key;

      request(url_in, function (error, response, body) {
        if (!error && response.statusCode == 200) {
          console.log(body); // Show the HTML for the Google homepage.
        }
      });


    }

  });

I just want to get the string that is the image url. But what i get back is an object representing the webpage.

Any help would be much appreciated.

It is not possible for you to get the image url as per the documentation as the url is not returned by the API.

https://lh3.googleusercontent.com/-B8FWOhhu2_k/VTdYJeFjRhI/AAAAAAAAAD8/JSJamjx4XyA/s1600-w400/

your image url however is already

imageurl = 'https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=' + PHOTO_REFERENCE + '&key=' + API_KEY;
// ^^^ this would return the image for you already (hence, your image url)

You can use this image url for 1,000 free requests per 24 hour period. You can increase this limit free of charge, up to 150,000 requests per 24 hour period, by enabling billing on the Google API Console

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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