我正在做我的第一个谷歌地图项目。我有多个标记出现,并且还使用了自定义标记。但是,单击标记时我无法使信息窗口工作!任何人都可以帮忙吗?
单击标记时,什么也没有发生 - 它甚至没有进入函数(我设置了控制台日志)。
<script type="text/javascript">
var map,
geocoder,
bounds,
address,
marker = [],
myLatlng = new google.maps.LatLng(40, -74);
function initialize() {
var mapOptions = {
center: myLatlng,
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: false,
scrollwheel: false,
navigationControl: true,
mapTypeControl: false,
scaleControl: true,
draggable: true
};
//styles
var styles = [{
"elementType": "geometry.fill",
"stylers": [
{ "visibility": "on" },
{ "hue": "#FF0000" },
{ "weight": 2 },
{ "gamma": 1 },
{ "lightness": 20 },
{ "saturation": 50 }
]
}];
map = new google.maps.Map(document.getElementById('map'), mapOptions);
geocoder = new google.maps.Geocoder();
map.setOptions({styles: styles});
var buildings = [
'76 Ninth Ave, New York, NY ',
'825 8th Ave, New York, NY ',
'127 E 23rd St, New York, NY '
];
var contentString = '<div id="content">test</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = {url:'<?php echo site_url(); ?>/wp-content/themes/theme/img/pointer2.png', scaledSize:new google.maps.Size(45, 72)};
for (var i = 0; i < buildings.length; ++i) {
(function(address) {
geocoder.geocode({ 'address': address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
marker += new google.maps.Marker ({
map: map,
position: results[0].geometry.location,
icon: marker
});
};
});
})(buildings[i]);
};
google.maps.event.trigger(map, 'resize');
google.maps.event.addListener(marker, 'click', function() {
console.log("test3");
infowindow.open(map,marker);
map.setZoom(8);
map.setCenter(marker.getPosition());
});
};
google.maps.event.addDomListener(window, 'load', initialize);