我按照本指南 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