【问题标题】:Getting the right URL of Google Place photo with angular使用角度获取 Google Place 照片的正确 URL
【发布时间】:2018-07-27 14:52:35
【问题描述】:

我使用 Angular 5 从 Google Place 检索照片 URL,如下所示:

...
var request = {
  location: new google.maps.LatLng(this.mylat,this.mylng),
  radius: 100,
  type: this.searchtype
};
let places = new google.maps.places.PlacesService(this.mymap);
places.nearbySearch(request, (results, status) => {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    results.forEach((place, index) => {
     var img_url = place.photos[0].getUrl({"maxWidth": 200, "maxHeight": 200}); // This URL works only for a few days..
    });
  }
})
...

此 URL 存储在我的 Firestore 数据库中以供以后使用。

问题: 谷歌地图提供了一个临时网址(仅在几天内有效)。 此 URL 重定向到“真实”(永久)URL。

示例:

临时网址:https://maps.googleapis.com/maps/api/place/js/PhotoService.GetPhoto?1sCmRaAAAAw_I6Al73qDad8ouQIOKMh38e_CRFB3bWj3hh7hBGeJB6YoWfeBfmDQkptvjuoval_kHABgM_yiJlDpmVF7XnMBu0LbhGbekdRCdezWbj4K2_h5scVqs_-peixhu-E83DEhBTeZpeIgJsAmzzbCyPdZg9GhRls6eH4OzIalD2Xy5CuIKrOxbduw&3u200&4u200&5m1&2e1&key=MYKEY&callback=none&token=26668

真实/永久(重定向到)网址:https://lh3.googleusercontent.com/p/AF1QipO4Xz37yaVeLaLL8ndNQKR93b5qvClsSis11koi=s1600-w200-h200

我怎样才能得到这个真实的 URL 而不是临时的?

【问题讨论】:

    标签: angular google-maps google-maps-api-3 google-places-api


    【解决方案1】:

    如果不使用 hacky 解决方案,我认为googleusercontent URL 是不可检索的。

    如果您需要的是图片的永久 URL,我建议使用 Google 的 Places web API 来检索图片引用,并且可以随时使用该引用来获取图片。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-22
      • 1970-01-01
      相关资源
      最近更新 更多