除非在初始页面加载后页面刷新,否则Google地图标记不会显示

时间:2017-06-28 19:01:31

标签: javascript google-maps google-maps-api-3

当初始页面加载时,地图会按原样显示,但在页面刷新一次之前,标记不会显示。任何见解将不胜感激。提前谢谢。

function initMap() {
var school = {lat: 38.901904, lng:  -77.021457};
var map = new google.maps.Map(document.getElementById('map'), { zoom: 17, 
center: school });

var marker = new google.maps.Marker({ position: school, map: map });

var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

var markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location,
label: labels[i % labels.length]
});
});

var markerCluster = new MarkerClusterer(map, markers, {imagePath:'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}
  var locations = [
 {lat: 38.901477, lng: -77.020735},
 {lat: 38.901258, lng: -77.021539},
 {lat: 38.903763, lng: -77.018829},
 {lat: 38.900974, lng:  -77.023124}
 ];

0 个答案:

没有答案