Search code examples
google-places-apigeturl

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


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. ***


Solution

  • 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-