Google Places Photos .GetUrl is adding width and height to url

天大地大妈咪最大 提交于 2019-12-02 02:59:39

问题


I'm trying to get images from google places. All is working for details: reviews, address... but when I try to get photos, I get a 404.

if(place.photos != null){
      for(var i = 0; i < place.photos.length; i++){
        var str = place.photos[i].getUrl({"maxWidth": 100, "maxHeight": 100});
        var res = str.replace("w100-h100-p", "p");
        self.pacPhotos.push({
          id : res

        });

      }
    }else {
      console.log("no photo");
    }
  }

This will return the list ok but the URL is formatted wrong. it comes out like this.

" https://lh3.googleusercontent.com/w100-h100-p/AF1QipN3xzffYDPCyEIWnvAQGd3RwNs2C14sVlSqrrAh=k "

What I gather it wants is this. " https://lh3.googleusercontent.com/p/AF1QipN3xzffYDPCyEIWnvAQGd3RwNs2C14sVlSqrrAh=k "

The only difference is the "w100-h100-"

*** There is a great work-around here from "Sulyman". I know it's not a long term solution as I'm sure google will fix their results (as discussed here Place API - getting place photo as marker icon )

For now I've adjusted the code above to reflect Sulymans suggestion. ***


回答1:


it seems like every API Key generates different path for example you got w100-h100-p and i got w200-p and the good news that this section whatever it is...is fixed so you can replace it with another string which is p

var str = place.photos[0].getUrl();
var res = str.replace(""w100-h100-p", "p");

or you can delete the w100-h100-



来源:https://stackoverflow.com/questions/44939403/google-places-photos-geturl-is-adding-width-and-height-to-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!