【发布时间】:2017-07-07 17:49:49
【问题描述】:
我遵循本指南 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);
这是 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-07-07============
感谢您的回答和修复
看来问题解决了。我的小提琴现在正在工作
https://issuetracker.google.com/issues/63298126
标记为已修复
好消息!我们已经解决了这个问题。谢谢你的耐心。
快乐的映射!
【问题讨论】:
-
FWIW,我目前遇到了完全相同的问题。可能是 Google 端的临时问题。
标签: google-maps google-places-api