我有一个"谷歌地图代码"包含在网站的每个页面中。在索引页面上一切正常,但是当我加载其他页面时,"代码"似乎跳过标记设置(不执行setMarkers函数)。是否存在缓存问题?
这是我的代码
function initialize(){
alert('start');
var mapOptions = {
zoom: 13,
scrollwheel: false,
center: new google.maps.LatLng(<?php print $general_latitude.','.$general_longitude;?>),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);
setMarkers(map, places);
alert('start done');
}
function setMarkers(map, locations) {
//alert('set markers');
var shadow = {
url: '<?php print get_template_directory_uri().'/css/css-images/shadow.png'; ?>',
size: new google.maps.Size(59, 59),
origin: new google.maps.Point(0,0),
anchor: new google.maps.Point(16, 59)
};
var shape = {
coord: [1, 1, 1, 38, 38, 59, 59 , 1],
type: 'poly'
};
var boxText = document.createElement("div");
var myOptions = {
content: boxText
,disableAutoPan: true
,maxWidth: 700
,pixelOffset: new google.maps.Size(-90, -450)
,zIndex: null
,closeBoxMargin: "-13px 0px 0px 0px"
,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
};
infoBox = new InfoBox(myOptions);
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
shadow: shadow,
icon: custompin(beach[8]),
shape: shape,
title: beach[0],
zIndex: beach[3],
image:beach[4],
price:beach[5],
type:beach[6],
type2:beach[7],
infoWindowIndex : i
});
gmarkers.push(marker);
google.maps.event.addListener(marker, 'click', function() {
infoBox.setContent('<div class="info_details">'+this.image+' <h2>'+this.title+'</h2> <div class="prop_details">'+this.type+' for '+this.type2+' - '+this.price+'</div>' );
infoBox.open(map, this);
map.setCenter(this.position);
map.panBy(380,-190);
});
}//end for
}// end setMarkers