我按照本指南 https://developers.google.com/maps/documentation/javascript/places#places_photos 创建地点照片作为标记图标。这是我的地图初始化代码:放置API - 获取地点照片作为标记图标
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);
这是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})
});
}
函数将创建常规标记,如果地方的照片无效。但对于现有的照片的地方,我得到这个错误:
无法加载资源:服务器用)的404状态( lh3.googleusercontent.com/w35-h35-p/AF1QipOIL6GVVmtqp_cw_hBEQxdILZSa8poMO0HAqFHd=k
回应 而地图只显示常规标记。 我做错了什么?
这是小提琴http://jsfiddle.net/v90fmrhp/
==========更新2017年7月7日============
感谢您的答案和修复
看来问题解决了。现在我的小提琴正在 https://issuetracker.google.com/issues/63298126
标记为已修复
好消息!我们已经解决了这个问题。谢谢你的耐心。
快乐贴图!
FWIW,我目前遇到完全相同的问题。可能是Google的暂时性问题。 – deceze