Google Places Photos .GetUrl为网址添加了宽度和高度 [英] Google Places Photos .GetUrl is adding width and height to url

查看:118
本文介绍了Google Places Photos .GetUrl为网址添加了宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Google地方获取图片.所有人都在寻找详细信息:评论,地址...,但是当我尝试获取照片时,我得到了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");
    }
  }

这将返回列表,但URL格式错误.像这样出来

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

我想要的是这个. " https://lh3.googleusercontent.com/p/AF1QipN3xzcYaA<2Q14 /p>

唯一的区别是"w100-h100-"

***"Sulyman"在这里有一个很好的解决方法.我知道这不是一个长期的解决方案,因为我敢肯定Google会解决他们的问题(如此处解决方案

似乎每个API密钥都会生成不同的路径 例如,您得到了w100-h100-p而我得到了w200-p 好消息是此部分无论如何都已修复,因此您可以将其替换为另一个字符串p

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

,或者您可以删除w100-h100-

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

解决方案

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-

这篇关于Google Places Photos .GetUrl为网址添加了宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆