我遇到了我的 infowindows 位置的问题。我在 for 循环中生成标记,但是当我单击信息窗口时,位置始终设置为最后生成的标记。不过内容是对的。这绝对是一个范围界定问题,还有一个 Drupal Ajax 调用可以获取内容(不包含任何位置信息)。任何人都可以帮忙吗?这是for循环:
for ( markerItem in data ) {
var icon = icons[data[markerItem][3]].mouseOutIcon;
var image = icons[data[markerItem][3]].mouseOverImage;
var latlng = new google.maps.LatLng( data[markerItem][0], data[markerItem][1] );
var marker = new google.maps.Marker({
icon:icon,
clickable:true,
position: latlng,
map: map,
draggable:false,
title: data[markerItem][2]
});
marker.mapid = mapid;
marker.mid = data[markerItem][4];
google.maps.event.addListener(marker,'click',function(latlng) {
$.get('/map-info/'+this.mapid+'/'+this.mid, null, function(response) {
console.log('first' + marker.getPosition());
var result = Drupal.parseJson(response);
if ( result.status == 0 ) {
if(infowindow != null) {
infowindow.close();
}
infowindow = new google.maps.InfoWindow({
content: result.html
//position: marker.getPosition()
});
infowindow.open(map,marker);
}
});
google.maps.event.addListener(marker, 'mouseover', function(latlng) {
this.setImage( this.mouseOverImage );
});
google.maps.event.addListener(marker, 'mouseout', function(latlng) {
this.setImage( this.mouseOutImage );
});
});
marker.mouseOverImage = image;
marker.mouseOutImage = icon.image;
gmap.overlays.push( marker );
marker.setMap(map);
if ( checkboxState[data[markerItem][3]] ) {
marker.setMap(map);
}
else {
marker.setMap(null);
}
}
});
}
else {
console.log('inside else');
var lat3 = gmap.oldBounds.getSouthWest().lat();
var lng3 = gmap.oldBounds.getSouthWest().lng();
var lat4 = gmap.oldBounds.getNorthEast().lat();
var lng4 = gmap.oldBounds.getNorthEast().lng();
$.get('/map-markers/'+mapid+'/'+lat1+'/'+lng1+'/'+lat2+'/'+lng2+'/'+lat3+'/'+lng3+'/'+lat4+'/'+lng4, null, function(response) {
var result = Drupal.parseJson(response);
var data = result.markers;
for ( var i = 0; i < 4; i++ ) {
icons.push( { mouseOutIcon: Drupal.gmap.getIcon('boilers', i), mouseOverImage: mouseOverImage(Drupal.gmap.getIcon('boilers', i).image)});
}
var gmap = Drupal.gmap.getMap(mapid);
for ( markerItem in data ) {
var icon = icons[data[markerItem][3]].mouseOutIcon;
var image = icons[data[markerItem][3]].mouseOverImage;
var latlng = new GLatLng( data[markerItem][0], data[markerItem][1] );
var marker = createMarker(latlng, {icon: icon, title:data[markerItem][2], clickable:true, draggable:false }, data[markerItem][4] );
marker.mouseOverImage = image;
marker.mouseOutImage = icon.image;
gmap.overlays.push( marker );
map.addOverlay( marker );
if ( checkboxState[data[markerItem][3]] ) {
//marker.show();
}
else {
//marker.hide();
}
}