How to get a picture of a place from google maps or places API

前端 未结 5 1935
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 07:11

I\'m using Google Places API to retrieve data about places, but couldn\'t find how to get a picture of that place, Google Places API just provides

5条回答
  •  执念已碎
    2020-12-13 07:52

    1. First get the photo_reference from the response:

       var photoRef;
       if (data.results[i].photos && Array.isArray(data.results[i].photos)) {
       photoRef = data.results[i].photos[0].photo_reference;
       }
      
    2. Use the Google Photos API endpoint to GET the place photo/picture:

    https://maps.googleapis.com/maps/api/place/photo?maxwidth=960&photoreference="+ photoRef +"&key=AIzaSyBp0cy7ti0z5MJMAwWiPMNvbJobmWYGyv4' alt=''/>

    1. See for yourself:

提交回复
热议问题