放置API - 将地点照片作为标记图标

zek*_*kai 1 google-maps google-places-api

我按照本指南 https://developers.google.com/maps/documentation/javascript/places#places_photos 将地方照片创建为标记图标.这是我的地图初始化代码:

var map;

function initMap() {
    // Create a map centered in Pyrmont, Sydney (Australia).
      map = new google.maps.Map(document.getElementById('map'), {
        center: {lat: -6.920812, lng: 107.604116},
        zoom: 13
      });

      var request = {
        location: map.getCenter(),
        radius: '5000',
        type: ['shopping_mall']
      };

      var service = new google.maps.places.PlacesService(map);
      service.textSearch(request, callback);
}

// Checks that the PlacesServiceStatus is OK, and adds a marker
// using the place ID and location from the PlacesService.
function callback(results, status) {
  console.log(results);
  if (status == google.maps.places.PlacesServiceStatus.OK) {
      for (var i = 0; i < results.length; i++) {
        var place = results[i];
        createPhotoMarker(place);
      }
  }
}

google.maps.event.addDomListener(window, 'load', initMap);
Run Code Online (Sandbox Code Playgroud)

这是createPhotoMarker函数

function createPhotoMarker(place) {
      var photos = place.photos;
      if (!photos) {
        var marker = new google.maps.Marker({
            map: map,
            position: place.geometry.location,
            title: place.name
          });
          return;
      }

      var marker = new google.maps.Marker({
        map: map,
        position: place.geometry.location,
        title: place.name,
        icon: photos[0].getUrl({'maxWidth': 35, 'maxHeight': 35})
      });
}
Run Code Online (Sandbox Code Playgroud)

如果地方照片不可用,该功能将创建常规标记.但是对于有照片的地方,我收到此错误:

无法加载资源:服务器响应状态为404() lh3.googleusercontent.com/w35-h35-p/AF1QipOIL6GVVmtqp_cw_hBEQxdILZSa8poMO0HAqFHd=k

并且地图仅显示常规标记.我做错了什么?
这是小提琴http://jsfiddle.net/v90fmrhp/

==========更新2017-07-07 ============

感谢您的答案和解决方案
似乎问题已经解决.我的小提琴现在正在运行 https://issuetracker.google.com/issues/63298126

被标记为固定
好消息!我们已经解决了这个问题.谢谢你的耐心.

快乐的映射!

a.x*_*xin 7

看起来您所看到的错误是由Google方面的某些问题引起的.它也影响了其他一些用户,看看他们的公共问题跟踪器:

感谢您报告此问题.我们验证了它,我们会继续跟踪它. https://issuetracker.google.com/issues/63298126

更新(2017-07-06):

对此的修复现在进入我们的发布过程,应该很快就会出来 - 最迟可能是周一. https://issuetracker.google.com/issues/63298126#comment13